android - How to retrieve JSONOBJECT which is inside JSONArray -


this java code retrieve data json

     res = out.tostring();                         jsonarray arrjsonarray=new jsonarray(res);                         (int = 0; < arrjsonarray.length(); i++) {                             jsonobject object = arrjsonarray.getjsonobject(i);                             data data=new data();                             data.setname(object.getstring("slug"));                             data.setmsg(object.getstring("modified"));                             data.setlocation(object.getstring("type"));  // want show data inside offer_shop_details. 

//like afflshop_address, afflshop_email, please me.

jsonobject authore = object.getjsonobject("offer_shop_details");  string authore1 = authore.getstring("afflshop_address"); data.setlocation(object.getstring(authore1));                              itemlist.add(data);                         } 

this jsonarray without object name have retrieved data inside jsonarray. not able retrieve data inside jsonobject inside main jsonarray. below code snippet.

   [{     id: 482,     title: "sample offer",     status: "publish",     type: "offers",     author: {     id: 1,     username: "bm",     name: "bm",     first_name: "",     last_name: "",     nickname: "bm",     slug: "bm",     url: "",     avatar: "http://0.gravatar.com/avatar/81ff187fd3ab62858b098258fb3f0479?s=96",     description: "",     registered: "2015-01-11t07:25:06+00:00",     meta: {     links: {     self: "http://titusandbindu.com/bm/wp-json/users/1",     archives: "http://titusandbindu.com/bm/wp-json/users/1/posts"     }     }     }, offer_shop_details: { afflshop_days: [ "0", "1", "2", "3", "4", "5", "6" ], time_field_from: "09:00", time_field_to: "22:00", afflshop_address: "new extention seef mall, 1st floor, manama, bahrain", afflshop_website: "http://titusandbindu.com/bm/organic-foods-and-cafe/", afflshop_email: "ahmed@goodfood.bh", afflshop_contact: "3333286", afflshop_image_id: { id: "512", url: "http://titusandbindu.com/bm/wp-content/uploads/2015/03/test1.jpg" } } ] 

is json example purposes or actual json output? if it's output problem is not valid json. of fields need strings ... "id" : 482, etc. also, you're missing closing "}".

cut & paste json jsonlint.com , hit "validate" ;)


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -