How to extract Json data and get all the values in java? -


i trying display values below json,but using below code can able show 1 loop value @ time.

say if key, "name"

i getting in console

##-- name  :   abcd 

but need show data belongs keys "name" , "e_id"

can me solve issue?

thanks precious time!..

sample.java

 string strjson = "[\n    {\n        \"samplelist\": [\n            {\n                \"name\": \"abcd\",\n                \"e_id\": \"123\"\n            }\n        ]\n    },\n    {\n        \"samplelist\": [\n            {\n                \"name\": \"efgh\",\n                \"e_id\": \"456\"\n            }\n        ]\n    }\n]";    jsonarray jarr = new jsonarray(strjson); (int = 0; < jarr.length(); i++)                  {                      string str_alldata = jarr.getjsonobject(i).getstring("samplelist");                      jsonarray newjarr = new jsonarray(str_alldata);                      (int j = 0; j < jarr.length(); j++)                     {                          string name = newjarr.getjsonobject(j).getstring("name");                         string id   = newjarr.getjsonobject(j).getstring("e_id");                          system.out.println(">>-- name  :   "+name);                                                 system.out.println(">>-- e_id  :   "+id);                                              }                   } 

the internal loop using length of wrong array, try using

 jsonarray newjarr = new jsonarray(str_alldata);  (int j = 0; j < newjarr.length(); j++) { 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -