json - List of key values from JSONArray (java/android) -


i have json made of jsonarray's. how list of key strings jsonarrays?

for example:

{   "mainkey": [     {       "keyvalue1": [         {           "id": 9000,            "name": "john doe"         }       ]     },      {       "keyvalue2": []     },      {       "keyvalue3": []     },      {       "keyvalue4": []     }   ] } 

i want obtain arraylist keyvalue1, keyvalue2 , on. how should in java?

try this:

jsonobject obj = new jsonobject(yourjsonstring); jsonarray array = obj.getjsonarray("mainkey"); for(int n = 0; n < array.length(); n++) {     jsonobject keyobject = array.getjsonobject(n);     iterator<?> keys = keyobject.keys();     while( keys.hasnext() ) {         string key = (string)keys.next();         if ( obj.get(key) instanceof jsonarray ) {             system.out.println(key);         }     } } 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -