簡體   English   中英

如何在不知道名稱的情況下解析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.....
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM