java - Json array inside array retrieve values Android -


i m trying values jsonarray inside array, m able retrieve whole json values jsonarray not able retrieve values inside jsonarray. when convert jsonarray jsonobject values stored inside jsonarray. gives error: org.json.jsonexception: no value "banner"

here json code, verified json code jsonlint.com , showed json validate,

[  	{"code":"banner","moduletitle":0,  	  "banner":  		[  			{"image":"http://imageurl"},  			{"image":"http://imageurl"},  			{"image":"http://imageurl"}  		]  		  	}  ]

i m trying 3 hour no luck. m new in json , not know how json work, , read abut gson library json values. here java code.

  jsonarray jsonobj = null;              string image_url = "";              string banner_code ="";                try {                  jsonobj =new jsonarray(lib_function.getjsonurl( jsontags.top_banner_josn_urls));                  log.d("value retrun :","" +jsonobj);                //---vlaue coming , print in log ----//                               } catch (jsonexception e) {                  log.v("error in parser :", " " + e);                  log.d("no value retrun :", "failed convert");              }                try{                      jsonobject jo = new jsonobject();                      jsonarray ja = new jsonarray();                      // populate array                      jo.put("arrayname", jsonobj);                      jsonarray subarray = jo.getjsonarray("banner");                  image_url= subarray.getstring(integer.parseint("image"));                      log.d("banner code",""+subarray);              }catch(exception e)              {                  log.d("not working",""+e);              }

i folllow question luck: how parse json array inside json array in android

if suggest, m doing wrong appreciate. or let me know, can more information json

update give precious time answering stupid question. answers correct , can accept 1 answer. big all

here:

jsonobject jo = new jsonobject(); jsonarray ja = new jsonarray(); // populate array jo.put("arrayname", jsonobj); 

because parsing jsonobj jsonarray no need create new jsonarray , jsonobject extract jsonobj. remove above 3 lines.

banner jsonarray inside jsonobject contained jsonobj jsonarray, as:

   jsonobject jsonobject=jsonobj.optjsonobject(0);     jsonarray subarray = jsonobject.getjsonarray("banner");     // code key `jsonobject`    string strcode=jsonobject.optstring("code");     // images urls `subarray`     for(int index=0;index<subarray.length();index++){       jsonobject imgjsonobject=subarray.optjsonobject(index);       // image urls       string strimgurl=imgjsonobject.optstring("image");       }  

also, if jsonobj jsonarray contains multiple jsonobject's use for-loop iterate it.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -