java - Need some assistance trying to parse this JSON response from our backend server -


currently working on android app , need on how can go extracting subfields within responses field of json object:

pic of json object

currently doing following extract of other fields:

 jsonobject json = new jsonobject(response2);  int id = json.getint("id");  string desc = json.getstring("description");  jsonobject json2 = json.getjsonobject("owner");  string username = json2.getstring("username"); 

you need create logic parse data. every item json string in jsonobject created

jsonobject json = new jsonobject(response2); 

you're on right track you're doing. use corresponding methods available in jsonobject , jsonarray classes move through object.

start main object

{                              // <-- main object (aka jsonobject json = new jsonobject(response2))     "id": 1,                   // pull id use json.getint("id");     "title": "some text here",  // pull title use json.getstring("title");     ...     "owner": {                 // here's logic part, owner itself, json object. must extract , parse through it.                                // pull "owner" json object, use jsonobject ownerobject = json.getjsonobject("owner");         "userid": 1,           // use ownerobject pull it's values. ownerobject.getint("userid");         "username": "testinguser",  // pull username use ownerobject.getstring("username");         ...     } ... } 

if it's array, example:

"somejsonarray": [{ "id": 1, "username": "testinguser1" }, { "id": 2, "username": "testinguser2" }] 

then call:

jsonarray somejsonarray = getjsonarray("somejsonarray"); // each object array. jsonobject object1 = somejsonarray.getjsonobject(0); jsonobject object2 = somejsonarray.getjsonobject(1); 

or if array contains string, example:

"somekey": [ 23, 435, 123, 6345, 123 ] 

then call:

jsonarray somekeyarray = getjsonarray("somekey"); (int = 0; < somekeyarray.length(); i++) {     // extract value.     int itemvalue = somekeyarray.getint(i); } 

the data there, have parse it.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

android - Keyboard hides my half of edit-text and button below it even in scroll view -

css - Make div keyboard-scrollable in jQuery Mobile? -