我的以下json数据:
{
"Alex": {
"id": "54e23a2331ac67b1490d87b8",
"desc": "bla bla",
"no": 2
},
"Kodie": {
"id": "54e23a2331ac67b1490d87b9",
"desc": "bla bla",
"no": 13
},
"Lache": {
"id": "54e23a2331ac67b1490d87af",
"desc": "bla bla",
"no": 89
}
}
如何在android系统中使用以下代码?
JSONObject object = new JSONObject(data);
for (int i = 0; i < object.length(); i++) {
//desc = object.getString("desc");
}
抱歉,我可以告诉你很多,因为我的英语非常糟糕。
答案 0 :(得分:12)
try {
JSONObject json = new JSONObject(data);
Iterator<String> temp = json.keys();
while (temp.hasNext()) {
String key = temp.next();
Object value = json.get(key);
}
} catch (JSONException e) {
e.printStackTrace();
}
答案 1 :(得分:5)
谢谢@oldfell;
JSONObject object = new JSONObject(json);
Iterator keys = object.keys();
while(keys.hasNext()) {
String dynamicKey = (String)keys.next();
JSONObject line = object.getJSONObject(dynamicKey);
String desc = line.getString("desc");
}
我用这种方式解决了这个问题