-2

I got stuck in parsing this JSON, I has read a some references in GitHub or google and not same for this case, can anyone give me guided or references


{
    "index":
          {
            "data":[
            {
                "id":1,
                "name":"John",
                "room":31
            }
        ]
    }
}

EDIT: we has found a more simple json format The solve by me

 {
            "data":[
            {
                "id":1,
                "name":"John",
                "room":31
            }
        ]
    }






 try {
                            JSONObject jsonArray = new JSONObject(response);
                            JSONArray list = jsonArray.getJSONArray("data");
                            for (int i = 0; i <list.length(); i++) {
                                String id= list.getJSONObject(i).getString("id");
                                String name = list.getJSONObject(i).getString("name");
                                String room= list.getJSONObject(i).getString("room");
                                KItem KTItem = new KasusItem(id,name,room);
                                kItemList.add(KTItem);
                            }



1 Answers1

0
JSONArray data = JSONObject(response).getJSONObject("index).getJSONArray("data);

for(int i=0; i<data.length; i++){
   JSONObject obj = data.getJSONObject(i);   
   String id = obj.getString("id");
   String name = obj.getString("name");
}
  • 1
    Your code has a syntax error, in addition, please don't post only code as answer, but include an explanation what your code does and how it solves the problem of the question. Answers with an explanation are usually of higher quality, and are more likely to attract upvotes. – Mark Rotteveel Mar 22 '20 at 09:31
  • the error maybe because less a " in index and data? – Harun Arrosyid Mar 23 '20 at 14:27
  • Mark Rotteveel i am not giving any spoon feeding to you guyz – Syed Minhaj Ali Mar 24 '20 at 08:51