android - How to access values returned from JSON Object -


so i'm working returned values json object , i'm trying return values of 1 of keys. json object this.

{"options":[{"picture":"http:\/\/example.com\/1.png", contact_id="1", name="tom"}, {"picture":"http:\/\/example.com\/2.png", contact_id="2", name="jess"}]} 

now i'm handling in android app , when have final static string called tag set options

private static final string tag = "options"; 

and use log json values this

log.d("friends name", jsn.getstring(tag)); 

i first result

{"options":[{"picture":"http:\/\/example.com\/1.png", contact_id="1", name="tom"},      {"picture":"http:\/\/example.com\/2.png", contact_id="2", name="jess"}]} 

however i'm trying access names , don't know how to.

i tried setting tag options[0].name first name gave me error

jsonexception : no value options[0].name

i'm bit lost here.

if talking json string have posted not valid json.

it should follows.

{     "options": [         {             "picture": "http://example.com/1.png",             "contact_id": "1",             "name": "tom"         },         {             "picture": "http://example.com/2.png",             "contact_id": "2",             "name": "jess"         }     ] } 

then write below snippet fetch name.

jsonobject android = new jsonobject(json_string);  jsonarray array = android.getjsonarray("options");  (int = 0; < array.length(); i++) {     log.i("name", array.getjsonobject(i).getstring("name")); } 

Comments