android - have issue in getting proper responce from for-loop -
i getting data json using for-loop. here code:
try { jsonobject jsonobj=new jsonobject(strri); privacy_setting_ozone_feed obj=new privacy_setting_ozone_feed(); jsonarray=jsonobj.getjsonarray("setting"); jsonarray jsonarray4=jsonobj.getjsonarray("blocklist"); log.d("ads", jsonarray4.tostring()); for(int i=0;i<jsonarray.length();i++) { jsonobject jsoninnerobj=jsonarray.getjsonobject(i); try { obj.strvalue=jsoninnerobj.getstring("value"); }catch(exception e) { } try { obj.str_name=jsoninnerobj.getstring("name"); }catch(exception e) { } } (int j=0; j<jsonarray4.length(); j++)//----------(loop) { jsonobject jobject = jsonarray4.getjsonobject(j); try { obj.str_image=jobject.getstring("image"); log.d("sadsa", obj.str_image); }catch(exception e) { } try { obj.str_blockname=jobject.getstring("name"); log.d("test", obj.str_blockname); }catch(exception e) { } arr.add(obj); //-------------------(1) } } catch (jsonexception e) { // todo auto-generated catch block e.printstacktrace(); } return arr;//--------------(2) }
at place arr.add(obj); geting exact value json, if there 3 different values getting proper 3 values... @ return point, getting last value coming json loop. please let me know mistake doing here.
you initializing obj
object once, because of 1 reference modifying results in having same value in entry. try calling constructor in loop. solve problem.
Comments
Post a Comment