java - Parsing JSON array from URL when data schema is unknown at compile time -


i trying finish part of android application enables user enter url, , pull json array data it. application takes users url, , stores string looks this:

{ "name": "demo", "currentdistance": "0", "goals": [     {         "goal": {             "depth": "2",             "goal": "2"         },         "goal": {             "depth": "6",             "goal": "4"         },         "goal": {             "depth": "4",             "goal": "3"         }     } ] 

}

now have found many solutions (such this) work great, assume know ahead of time key values are. trying make json array source not known @ compile time, , range 1 key many.

i have tried saving string json object, using .put add array, not use if data has more 1 key. have able parse , treat true json array once have gotten data url.

i not concerned error checking on url right now, assume url given app proper http json text shown above.

any appreciated!

cannot. if don't know json schema, cannot parse pojo (plain old java object) because java strongly-type language. can parse custom json string object in dynamic languages such javascript.

in case want browse key-value of json string.sample code

jobject = new jsonobject(contents.trim()); iterator<?> keys = jobject.keys();  while( keys.hasnext() ) {     string key = (string)keys.next();     if ( jobject.get(key) instanceof jsonobject ) {      } } 

hope :)


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -