android - How to get Data from following type of JSONObject? There is no JSONArray -


i got below jsonobject firebase.

there no jsonarray in response.

how can main jsonobject loop.?

is below json response valid? or have convert jsonarray ?
know how inner jsonobject if there jsonarray.

{     "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 2 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             }         }     } } 

note : 10% of total response.

the json provided valid, if know keys can say

obj.getjsonobject("key"); 

if don't know keys, can use iterator

jsonobject j=new jsonobject();     iterator<string> iterator=j.keys();     while (iterator.hasnext())     {         string key=iterator.next();        jsonobject newobj= j.getjsonobject(key);     } 

to fetch nested objects.


Comments