How to get the value of the element "number1" from JSON

String json ={"id":1,"result": [{"id": {"number1": "25","text1":"abcdef"},"name1":"Ivan"}, {"id2": {"number2": "25","text2":"abcdef"}, "name2":"Ivan"}, {"id3": {"number3": "25","text3":"abcdef"}, "name3":"Ivan"}; 

I'm trying this:

 JSONObject obj = new JSONObject(json); JSONArray data = obj1.getJSONArray("result"); JSONObject obj2= data.getJSONObject(1); 

Thanks in advance!

  • Which library is used? - arg

1 answer 1

 obj1 .getJSONArray("result") .getJSONObject(0) .getJSONObject("id") .getString("number1") 
  • one
    Numbering from scratch begins. So either getJSONObject(0) , or further property names need to be fixed. - andreycha
  • thank. Only everything works if the last line is removed. - Mack
  • @andreycha: Yes, of course, thanks a lot for the tip! - Igor Chubin