本文是小编为大家收集整理的关于我如何在不知道名称的情况下解析JSONObject?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。
问题描述
我有这样的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..... } }
问题描述
I have json string like this:
{ "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 } }
How can I parse JSONObject without knowing the name "2" just moving to the next array?
推荐答案
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..... } }