Android(JSONObject)如何获取每个密钥
如果我有一个JSON:Android(JSONObject)如何获取每个密钥,android,json,jsonobject,Android,Json,Jsonobject,如果我有一个JSON: {"list_path":{"149":{"1610":{"file":[]},"1599":{"1600":{"1604":{"1605":{"file":[]},"file":[]},"1601":{"1602":{"file":["f485","f484","f482","f481","f480","f479","f478","f477"]},"file":[]},"file":[]},"file":[]},"1609":{"file":[]},"1607":{"f
{"list_path":{"149":{"1610":{"file":[]},"1599":{"1600":{"1604":{"1605":{"file":[]},"file":[]},"1601":{"1602":{"file":["f485","f484","f482","f481","f480","f479","f478","f477"]},"file":[]},"file":[]},"file":[]},"1609":{"file":[]},"1607":{"file":[]},"1608":{"file":[]},"1606":{"file":[]},"file":[]}}}
但我不知道钥匙。我怎样才能拿到每把钥匙
我尝试使用String key=iter.next()代码>但它只能获得一个密钥
就像我在149年写的一样。我要159916061607160816091610档案
请帮帮我。多谢各位
JSONParser jParser = new JSONParser();
JSONObject jsons = jParser.getJSONFromUrl("http://ap2.finance.xcom.tw:8080/app/?m=z8Ga37UPPQbEDMxR&mode=get_list&user_id=1");
try {
JSONObject status = jsons.getJSONObject("list_path");
Iterator iter = status.keys();
while(iter.hasNext()) {
String key = (String)iter.next();
try {
Object value = jsons.get(key);
} catch (JSONException e) {
Log.d( "Json", "hasNext error");
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
试试这个:
JSONObject obj = new JSONObject(yourJsonString);
JSONObject listPathObject = obj.getJSONObject("list_path");
JSONObject object149 = listPathObject.getJSONObject("149");
Iterator<String> iter = object149.keys(); //This should be the iterator you want.
while(iter.hasNext()){
String key = iter.next();
}
通过
然后检查有多少JSON对象。
您的代码就在“列表路径”中,只有一个键。
但是在“149”JSON对象中有6个对象wd integer key和一个带有“file”keyname。您没有得到“149”的对象
1610
1599
1609
1607
1608
1606
file