Как я могу получить полный список, хранящийся в моем arraylist? мой JSON являетсяПоказывает, что он закончил ArrayList?
{"Children": [{"Child": {"childID": "1001","childName": "aaa","trackerID": "t1"}},{"Child": {"childID": "1002","childName": "bbb","trackerID": "t2"}}]}
код:
JSONObject json =new JSONObject(line);
int len=json.getJSONArray("Children").length();
System.out.println(len); //len is 2
ArrayList Children=new ArrayList();
Map store=new HashMap();
String[] cid=new String[len];
String[] name=new String[len];
for(int i=0;i<len;i++)
{
cid[i]=json.getJSONArray("Children").getJSONObject(i).getJSONObject("Child").get("childID").toString();
name[i]=json.getJSONArray("Children").getJSONObject(i).getJSONObject("Child").get("childName").toString();
store.put("ID", cid[i]);
store.put("Names",name[i]);
}
Children.add(store);
System.out.println(Children);
Выход я получаю [{Names=bbb, ID=1002}]
, но есть много других идентификаторов и выход names's.Expected является [{Names=aaa, ID=1001}],[{Names=bbb, ID=1002}]
Как я могу напечатать все это?
опубликовать также JSON и ожидаемый выход, может быть лучшее решение доступно –