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
    }
  ]
2
  • what you tried, so far ? Commented Aug 24, 2013 at 8:37
  • for Json parser which class you are using? Commented Aug 24, 2013 at 8:44

4 Answers 4

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"));
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can use:

JSONArray a = new JSONArray(myJsonString);

Comments

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");
}

Comments

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));
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.