2

I have a Json Array as string with no name and I want to parse it how can i do it in android ?

My JsonArray is :

  [
  { 
    "categoryId":1,
    "Title":"Rock",
    "songs":null
  },
    { 
    "categoryId":2,
    "Title":"Jaz",
    "songs":null
    }
  ]
Maha Mahmoud
  • 65
  • 1
  • 2
  • 5

4 Answers4

11

Try this..

JSONArray jsonarray = new JSONArray(json);

for (int i = 0; i < jsonarray.length(); i++) {

       JSONObject jsonobj = jsonarray.getJSONObject(i);

      System.out.println("categoryId : " + i + " = " + jsonobj.getString("categoryId"));
       System.out.println("Title : " + i + " = " + jsonobj.getString("Title"));
       System.out.println("songs : " + i + " = " + jsonobj.getString("songs"));
}
Hariharan
  • 24,741
  • 6
  • 50
  • 54
1

You can use:

JSONArray a = new JSONArray(myJsonString);
Henry
  • 42,982
  • 7
  • 68
  • 84
1

Try this:

JSONArray arr = new JSONArray(jsonString);

for (int i = 0; i < arr.length(); i++) {
    JSONObject obj = arr.getJSONObject(i);

     String title = obj.getString("Title");
}
Kavin
  • 544
  • 3
  • 5
0

Do like this

JSONArray jArr = new JSONArray(jsonString);

for (int i = 0; i < jArr.length(); i++) {
    Syste.out.println("Object : " + i + " = " + jArr.getJSONObject(i));
}
Biraj Zalavadia
  • 28,348
  • 10
  • 61
  • 77