Get String From Json With Nested Json Object And Nested Json Arrays With Multiple Json Object, In Android
I need to access as String all the single parameters contained in a complex Json. for example String people=...; String idPeople=...; etc. I have tried to use the JS
Solution 1:
I've not tried. But i guess it may work.
JSONObject obj = newJSONObject(jsonString);
String id = obj.getString("id");
String error = obj.getString("error");
JSONObject result = obj.getJSONObject("result");
int nPeople = result.getInt("nPeople");
JSONArray people = result.getJSONArray("people");
for(int i = 0 ; i < people.length() ; i++){
JSONObject p = (JSONObject)people.get(i);
String namePeople = p.getString("namePeople");
...
}
Solution 2:
if we call the json you post myJsonString,
JSonObjectobj=newJSonObject(myJsonString);
JSonObjectresult= obj.getJSONObject("result");
JSonArraypeople= result.getJSONArray("people");
intnumOfPeople= result.getInt("nPeople");
Baca Juga
Post a Comment for "Get String From Json With Nested Json Object And Nested Json Arrays With Multiple Json Object, In Android"