Hello!

Please help me write this record:

{"stts":{"s":1,"td":{"cid":"72345","zn":"njiw"},"st":true}} 

Need to access all items. How can I do that?

I have been suffering for two days with JSONObject and getJSONArray:

 //response - строка ответа сервера private JSONObject json; private JSONArray values; json = new JSONObject(response); //Тут все ок values = json.getJSONArray("stts");//А тут ловлю краш 

Log:

  11-07 17:19:15.491: W/System.err(271): org.json.JSONException: Value {"s":1,"td":{"cid":"72345","zn":"njiw"},"st":true} at s of type org.json.JSONObject cannot be converted to JSONArray 
  • Well, tell me how you suffer in the details. :-) - Chad
  • @ Chad ok) Updated) - M11
  • @ Chad I use json_encode (PHP) and it returns like this, additions like json_encode (array (json => $ json)) did not lead to anything. Returns as I wrote above. The challenge is to get all the values. And how to do it with those elements that inside the stts I have no idea. - M11 Nov.
  • Once again - inside you is not an array, but a hash. Take as JSONObject from jsonObject'a. - Chad
  • @ Chad can see how it looks. Just hard to imagine. - M11

1 answer 1

So your stts is not an array, but a JSONObject too, take it:

json.getJSONObject("stts");

an array is when [] i.e. {"stts":[{"s":1},{"td":...}]}