如何从以下类型的 JSONObject 中获取数据?没有 JSONArray
How to get Data from following type of JSONObject? There is no JSONArray
我从 Firebase
低于 JSONObject
。
没有任何JSONArray
响应。
如何通过循环获取所有主要 JSONObject
?
下面JSON
的回复有效吗?或者我必须转换成 JSONArray
?
如果有 JSONArray
.
,我知道如何获得内部 JSONObject
{
"Data": {
"inner_data": {
"key1": {
"chapter": "Chapter 1",
"key": "key",
"weight": 1
},
"key2": {
"chapter": "Chapter 2",
"key": "-KMa5xai7vMQtaDZ0b31",
"weight": 2
}
}
},
"Demo": {
"inner_demo": {
"key1": {
"chapter": "Chapter 1",
"key": "key",
"weight": 1
},
"key2": {
"chapter": "Chapter 2",
"key": "-KMa5xai7vMQtaDZ0b31",
"weight": 2
}
}
},
"Test": {
"inner_test1": {
"-KMa9JFjKuDNgf313Bzc": {
"key": "-KMa9JFjKuDNgf313Bzc",
"time": "10:33",
"topic": "Circles",
"url": "https://www.youtube.com/watch?v=yLVsv9kO5C8",
"weight": 1
}
},
"-inner_test2": {
"-KMa95pUP3bKtnoQaPg4": {
"key": "-KMa95pUP3bKtnoQaPg4",
"time": "15:26",
"topic": "Linear Equations in two Variables",
"url": "https://www.youtube.com/watch?v=Wpr3tddDw9s",
"weight": 1
}
},
"-inner_test3": {
"-KMa8i5mU9HUapf-wGDU": {
"key": "-KMa8i5mU9HUapf-wGDU",
"time": "05:38",
"topic": "Measurement of volumes",
"url": "https://www.youtube.com/watch?v=mbFwgu4xx40",
"weight": 1
}
},
"inner_demo_test": {
"key1": {
"chapter": "Chapter 1",
"key": "key",
"weight": 1
},
"key2": {
"chapter": "Chapter 2",
"key": "-KMa5xai7vMQtaDZ0b31",
"weight": 2
}
}
}
}
注意:这仅占总回复的 10%。
你提供的json是有效的,如果你知道密钥你可以简单地说
obj.getJSONObject("key");
如果你不知道键,你可以使用迭代器
JSONObject j=new JSONObject();
Iterator<String> iterator=j.keys();
while (iterator.hasNext())
{
String key=iterator.next();
JSONObject newObj= j.getJSONObject(key);
}
获取嵌套对象。
我从 Firebase
低于 JSONObject
。
没有任何JSONArray
响应。
如何通过循环获取所有主要 JSONObject
?
下面JSON
的回复有效吗?或者我必须转换成 JSONArray
?
如果有 JSONArray
.
JSONObject
{
"Data": {
"inner_data": {
"key1": {
"chapter": "Chapter 1",
"key": "key",
"weight": 1
},
"key2": {
"chapter": "Chapter 2",
"key": "-KMa5xai7vMQtaDZ0b31",
"weight": 2
}
}
},
"Demo": {
"inner_demo": {
"key1": {
"chapter": "Chapter 1",
"key": "key",
"weight": 1
},
"key2": {
"chapter": "Chapter 2",
"key": "-KMa5xai7vMQtaDZ0b31",
"weight": 2
}
}
},
"Test": {
"inner_test1": {
"-KMa9JFjKuDNgf313Bzc": {
"key": "-KMa9JFjKuDNgf313Bzc",
"time": "10:33",
"topic": "Circles",
"url": "https://www.youtube.com/watch?v=yLVsv9kO5C8",
"weight": 1
}
},
"-inner_test2": {
"-KMa95pUP3bKtnoQaPg4": {
"key": "-KMa95pUP3bKtnoQaPg4",
"time": "15:26",
"topic": "Linear Equations in two Variables",
"url": "https://www.youtube.com/watch?v=Wpr3tddDw9s",
"weight": 1
}
},
"-inner_test3": {
"-KMa8i5mU9HUapf-wGDU": {
"key": "-KMa8i5mU9HUapf-wGDU",
"time": "05:38",
"topic": "Measurement of volumes",
"url": "https://www.youtube.com/watch?v=mbFwgu4xx40",
"weight": 1
}
},
"inner_demo_test": {
"key1": {
"chapter": "Chapter 1",
"key": "key",
"weight": 1
},
"key2": {
"chapter": "Chapter 2",
"key": "-KMa5xai7vMQtaDZ0b31",
"weight": 2
}
}
}
}
注意:这仅占总回复的 10%。
你提供的json是有效的,如果你知道密钥你可以简单地说
obj.getJSONObject("key");
如果你不知道键,你可以使用迭代器
JSONObject j=new JSONObject();
Iterator<String> iterator=j.keys();
while (iterator.hasNext())
{
String key=iterator.next();
JSONObject newObj= j.getJSONObject(key);
}
获取嵌套对象。