Get String from json with nested json object and nested json arrays with multiple json object, in Android

后端 未结 2 880
伪装坚强ぢ
伪装坚强ぢ 2021-02-04 19:10

I need to access as String all the single parameters contained in a complex Json.

for example String people=...; String idPeople=...; etc.

2条回答
  •  被撕碎了的回忆
    2021-02-04 19:38

    I've not tried. But i guess it may work.

        JSONObject obj = new JSONObject(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");
            ...
        }
    

提交回复
热议问题