Android/java Parsing JSON with numbered data -


this question has answer here:

i have been looking parsing json data in java/android. unfortunately, there no json same mine. have json data include weird number, looks :

{ "formules": [{"1":     {   "formule": "linear motion",   "url": "qp1" },"2": {   "formule": "constant acceleration motion",   "url": "qp2" },"3": {   "formule": "projectile motion",   "url": "qp3" } } ] } 

please me how parse in java/android. thanks

try this

jsonobject jsonobject = new jsonobject(string); jsonarray jsonarray = jsonobject.getjsonarray("formules"); jsonobject jsonobject1 = jsonarray.getjsonobject(0); 

now can access object "1" as

jsonobject json = jsonobject1.getjsonobject("1"); 

or use iterator iterate below

iterator keys = jsonobject1.keys(); while(keys.hasnext()) {             // loop dynamic key             string currentdynamickey = (string)keys.next();             jsonobject json = jsonobject1.getjsonobject(currentdynamickey);          } 

let me know if works


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -