-3

Hello everyone I have a problem with JSON

   {  
     "browseResults":[  
       {  
         "id": "Simulation Examples.Functions.Random1"
       },
       {  
         "id": "Simulation Examples.Functions.Random2"
       },
       {  
         "id": "Simulation Examples.Functions.Random3"
       },
       {  
         "id":"Simulation Examples.Functions.Random4"
       }
     ],
     "succeeded": true,
     "reason": ""
  }

I wanna pull this as using that part of code but can't do it. What can I use instead of it?

JSONObject jsonObject=new JSONObject(result);
String main = jsonObject.getString("browseResults");
Log.i("Content2",main);
Kraylog
  • 7,383
  • 1
  • 24
  • 35
akms
  • 51
  • 1
  • 5

2 Answers2

2

JSON parsing will be :

JSONObject jsonObj = new JSONObject(result);

JSONArray bResults = jsonObj.getJSONArray("browseResults");

for (int i = 0; i < bResults.length(); i++) 
{
      JSONObject c = bResults.getJSONObject(i);

      String id = c.getString("id");

      Log.i("Content2",id);
}
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
1

Try following code to parse your data :

   JSONObject jsonObject = new JSONObject(result);
    try {

        JSONArray jsonArray = jsonObject.getJSONArray("browseResults");

        for(int i = 0 ; i < jsonArray.length() ; i++)
        {
           JSONObject id = jsonArray.getJSONObject(i);
        }

     } catch (JSONException e1) {

     e1.printStackTrace();

     }

     Log.i("Content2",jsonObject);
Vidhi Dave
  • 5,614
  • 2
  • 33
  • 55
Aj 27
  • 2,316
  • 21
  • 29