我如何在不知道名称的情况下解析JSONObject?[英] How can I parse JSONObject without knowing the name?

问题描述

我有这样的json字符串:

{  
    "2":{  
        "id":"2",
        "first":"3",
        "last":"2",
        "ilike":"1",
        "created_at":"2015-06-30 16:57:39",
        "liketo":"2",
        "firstname":"FirstName",
        "lastname":"LastName",
        "birthday":null
    }
}

如何在不知道名称"2"的情况下解析 JSONObject只是移动到下一个数组?

推荐答案

String json="" // place your json format here in double Quotes with proper escapes .......
jObject = new JSONObject(json.trim());
Iterator<?> keys = jObject.keys();

while( keys.hasNext() ) {
    String key = (String)keys.next();
    if ( jObject.get(key) instanceof JSONObject ) {
         // do what ever you want with the JSONObject.....
    }
}

本文地址:https://www.itbaoku.cn/post/978440.html