Android Volley does not loop through the whole JSON Objects -
help guys, trying parse nested json objects. when checked logcat not iterate next jsonobject of pasta. shows first jsonobject of
"name" : "creamy bacon mushroom", "details" : "", "price" : "", "image" : { "url" : "" }
after infinitely loops on , on again.
this json:
[ { "food" : { "pasta" : [ { "name" : "creamy bacon mushroom", "price" : 170, "details" : "creamyyy", "image" : { "url" : "/sad/uploads/food/images/1/food_pasta_creamybaconmushroom.jpg" } }, { "name" : "vigan longganisa penne", "price" : 169, "details" : "vigannnnn", "image" : { "url" : "/sad/uploads/food/images/2/food_pasta_viganlonganissapenne.jpg" } }, { "name" : "spanish sardine pesto", "price" : 168, "details" : "spanishhhhh", "image" : { "url" : "/sad/uploads/food/images/3/food_pasta_spanishsardinepesto.jpg" } } ] } }
]
this code:
stringrequest stringrequest = new stringrequest(url, new com.android.volley.response.listener<string>() { @override public void onresponse(string response) { try { jsonarray jsonarray = new jsonarray(response); for(int i=0;i<response.length();i++){ jsonobject jsonobject = jsonarray.getjsonobject(i); jsonobject jsonobjectfood = jsonobject.getjsonobject("food"); jsonarray jsonarraypasta = jsonobjectfood.getjsonarray("pasta"); log.d(stringconfig.log_tag, jsonarraypasta.tostring()); for(int j=0; j<jsonarraypasta.length();i++){ jsonobject jsonobject1 = jsonarraypasta.getjsonobject(j); string jsonname = jsonobject1.getstring("name"); string jsonprice = jsonobject1.getstring("price"); string jsondetails = jsonobject1.getstring("details"); jsonobject jsonobjectimage = jsonobject1.getjsonobject("image"); string jsonimage = jsonobjectimage.getstring("url"); log.d(stringconfig.log_tag, "name : " + jsonname); log.d(stringconfig.log_tag, "price : " + jsonprice); log.d(stringconfig.log_tag, "details : " + jsondetails); log.d(stringconfig.log_tag, "imageurl : " + jsonimage); } } } catch (jsonexception e) { e.printstacktrace(); } } }, new com.android.volley.response.errorlistener() { @override public void onerrorresponse(volleyerror error) { } }); requestqueue.add(stringrequest);
}
this logcat:
07-28 14:54:53.691 6222-6222/? d/sad: name : creamy bacon mushroom 07-28 14:54:53.691 6222-6222/? d/sad: price : 170 07-28 14:54:53.691 6222-6222/? d/sad: details : creamyyy 07-28 14:54:53.691 6222-6222/? d/sad: imageurl : /sad/uploads/food/images/1/food_pasta_creamybaconmushroom.jpg 07-28 14:54:53.691 6222-6222/? d/sad: name : creamy bacon mushroom 07-28 14:54:53.691 6222-6222/? d/sad: price : 170 07-28 14:54:53.691 6222-6222/? d/sad: details : creamyyy 07-28 14:54:53.691 6222-6222/? d/sad: imageurl : /sad/uploads/food/images/1/food_pasta_creamybaconmushroom.jpg 07-28 14:54:53.691 6222-6222/? d/sad: name : creamy bacon mushroom 07-28 14:54:53.691 6222-6222/? d/sad: price : 170 07-28 14:54:53.691 6222-6222/? d/sad: details : creamyyy 07-28 14:54:53.691 6222-6222/? d/sad: imageurl : /sad/uploads/food/images/1/food_pasta_creamybaconmushroom.jpg 07-28 14:54:53.691 6222-6222/? d/sad: name : creamy bacon mushroom 07-28 14:54:53.691 6222-6222/? d/sad: price : 170 07-28 14:54:53.691 6222-6222/? d/sad: details : creamyyy 07-28 14:54:53.691 6222-6222/? d/sad: imageurl : /sad/uploads/food/images/1/food_pasta_creamybaconmushroom.jpg 07-28 14:54:53.691 6222-6222/? d/sad: name : creamy bacon mushroom 07-28 14:54:53.691 6222-6222/? d/sad: price : 170 07-28 14:54:53.691 6222-6222/? d/sad: details : creamyyy 07-28 14:54:53.691 6222-6222/? d/sad: imageurl : /sad/uploads/food/images/1/food_pasta_creamybaconmushroom.jpg 07-28 14:54:53.691 6222-6222/? d/sad: name : creamy bacon mushroom 07-28 14:54:53.691 6222-6222/? d/sad: price : 170 07-28 14:54:53.691 6222-6222/? d/sad: details : creamyyy 07-28 14:54:53.691 6222-6222/? d/sad: imageurl :
/sad/uploads/food/images/1/food_pasta_creamybaconmushroom.jpg 07-28 14:54:53.692 6222-6222/? d/sad: details : creamyyy 07-28 14:54:53.692 6222-6222/? d/sad: name : creamy bacon mushroom 07-28 14:54:53.692 6222-6222/? d/sad: price : 170 07-28 14:54:53.692 6222-6222/? d/sad: details : creamyyy
change i++ j++ in inner for loop
Comments
Post a Comment