【发布时间】:2017-06-08 06:51:48
【问题描述】:
我有一个ArrayList,其中包含JSONArrays 的列表
staffArray = new ArrayList<JSONArray>();
JSONArray 的形式如下:
[
{
"id": "k40dn-dff02-mm1",
"name": "staff1",
"tel": "0123456789",
},
{
"id": "ch2mq-pmw01-ps6",
"name": "staff2",
"tel": "9876543210",
}
...
]
而ArrayList 将包含不同大小的JSONArray。
现在我想检查每个JSONArray 的ArrayList,如果它们包含相同的“id”值。所以说,如果ArrayList 有三种不同大小的JSONArray,我怎么知道它们每个都包含一个JSONObject,其中的“id”值相同。
到目前为止,我已经尝试过这个来提取字符串:
for(int i = 0; i < staffArray.size(); i++){
JSONArray jsonArray = new JSONArray();
jsonArray = staffArray.get(i);
for(int j = 0; j < jsonArray.length(); j ++){
JSONObject json = null;
try {
json = jsonArray.getJSONObject(j);
String id = json.getString("id");
} catch (JSONException e) {
e.printStackTrace();
}
}
}
【问题讨论】:
标签: java android json arraylist