0

I have a JSON array like this:

[
   {
     "stats": {
     "callQuality": 5,
     "audioRecvRemoteMute": false,
     "audioRecvLocalMute": true,
     },
     "rtpStatsList": [
     {
        "media": 1,
        "direction": 1,
        "content": true,
     }
   ],
   "timestamp": 1460208299000
   },
   {
      "stats": {
      "callQuality": 5,
      "audioRecvRemoteMute": false,
      "audioRecvLocalMute": true,
   },
   "rtpStatsList": [
   {
      "media": 1,
      "direction": 1,
      "content": true,
   }
   ],
  "timestamp": 1460208299000
 },
]

There are multiple elements (180 elements for e.g.) in the array. I need "media" and "direction" parameters under rtpStatsList. Any useful suggestion to parse the same using JAVA?

vadian
  • 253,546
  • 28
  • 306
  • 323
akshay_rao
  • 75
  • 1
  • 3
  • 2
    Many json parsing libraries exist. Consider google. maybe search for "json parser java". Consider the first link you find; it will be on an unfamiliar site, but is probably good. Here is the link http://stackoverflow.com/questions/2591098/how-to-parse-json-in-java – DwB Apr 10 '16 at 15:02

2 Answers2

0

Here Check this out

String data = EntityUtils.toString(httpResponse2.getEntity()); JSONArray js=new JSONArray(data) for(int i=0;i<js.length();i++) {

JSONObject total = js.getJSONObject(js);{ JSONArray rtpStatsList=total.getJSONArray("rtpStatsList"); for(int j=0;j<rtpStatsList.length();j++) {

                     `JSONObject jsonObject = rtpStatsList.getJSONObject(j);` 
                      media = jsonObject.getString("media");
                      direction = jsonObject.getString("direction");                  
                      }
                      }`
notTdar
  • 1,385
  • 2
  • 15
  • 34
0

Use this: http://theoryapp.com/parse-json-in-java/ You have an extensive explanation of:

  • Build a URL.
  • Read from the URL.
  • Build a JSON object for the content.
  • Retrieve the first result from an array of results.
  • Print out the information.
Antoine
  • 302
  • 1
  • 3
  • 18