【发布时间】:2018-12-11 08:41:13
【问题描述】:
我想得到数字“10449479”、“10449480”、“10449481”。
{
"xyz": {
"10449479": {
"a": "22",
"b": "33",
"c": " - "
},
"10449480": {
"a": "44",
"b": "55",
"c": " - "
},
"10449481": {
"a": "66",
"b": "77",
"c": " - "
}}}
我需要获取 keys() 因为它们是未知的。我怎样才能得到这些数字。请帮忙。
public void onResponse(JSONObject response) {//From Volley
try {
JSONObject jarray = response.getJSONObject("xyz");
Iterator<String> iter = jarray.keys();
while (iter.hasNext()) {
String key = iter.next();
try {
Object value = jarray.get(key);
} catch (JSONException e) {
// Something went wrong!
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
我只能获取每个键内的嵌套值,如
{
"a": "22",
"b": "33",
"c": " - "
}
//and other 2
如何获得左侧键。谢谢。
【问题讨论】:
-
对那个对象也做同样的事情。再次获取键,然后获取值。