我有这个JSON:
{
"id": 2643743,
"dt": 1485789600,
"clouds": {
"all": 90
}
}
在这个JSON中,我如何检查具有嵌套JSON的密钥?例如,如何检查云是否嵌套了JSON?
JSONObject json = readJsonFromUrl("http://samples.openweathermap.org/data/2.5/weather?q=London,uk&APPID=916c290adb437e1cc53eab01798225ed");
Iterator keys = json.keys();
Iterator inskeys = json.keys();
String keyStr = null;
while(keys.hasNext()) {
keyStr = (String) keys.next();
Object keyvalue = json.get(keyStr);
Object keyType = keyvalue.getClass().getSimpleName();
...
答案 0 :(得分:0)
这是一个简单的例子:
String JSON = "{\"id\":2643743,\"dt\":1485789600,\"clouds\":{\"all\":90}}";
JSONObject jsonObject = new JSONObject(JSON);
JSONObject getSth = jsonObject.getJSONObject("clouds");