android - How to retrieve data using json parsing when there are multiple inner nodes? -
i trying retrieve data using url
using json parsing
in android.
i have done following coding not able figure out how parse node present in inner node items
.
my json array , codes posted below. please guide me step step.
part of json array
[ { "items": [ { "id": "11", "item_id": "123", "item_name": "chicken cream soup", "price": "8", "currency": "aed", "category": "soup", "description": "creamy chicken soup garnish & side helpings", "unit": "2", "food_type": "non", "image_large": "/images_large/chickensoup.jpg", "image_thumb": "/images_large/chickensoup.jpg", "timestamp": "6/23/2014 9:49:43 pm", "promotion": "", "item_name_arabic": "حساء الطماطم", "item_name_russian": "", "currency_arabic": "درهم", "currency_russian": "", "description_arabic": "حساء الطماطم", "description_russian": "", "note": "", "nutritional_info": "", "extrafield_1": "", "extrafield_2": "", "preferncess": [ "no salt", "extra sugar" ], "preferncess_ids": [ "1", "2" ], "price": [ "4", "5" ], "preferncess_arabic": [ "لا الملح", "سكر اضافية" ] },
mainactivity.class
try { jsonobject jsonobj = new jsonobject(jsonstr); // getting json array node items = jsonobj.getjsonarray(tag_contacts); log.i("json node",""+items); // looping through contacts (int = 0; < items.length(); i++) { jsonobject c = items.getjsonobject(i); string id = c.getstring("id"); //string name = c.getstring(tag_name); log.w("myid", id); } catch (jsonexception e) { e.printstacktrace(); }
// fetch item array jsonarray itemobjectarray = jsonstr.getjsonarray("items"); (int = 0; < itemobjectarray.length(); i++) { // fetch item object @ position jsonobject itemobject = itemobjectarray.getjsonobject(i); // fetch values itemobject string idvalue = itemobject.getstring("id"); string notevalue = itemobject.getstring("note"); // fetch array jsonarrayprefobject = itemobject.getjsonarray("preferncess"); // iterate throgh array (int = 0; < prefobject .length(); i++) { jsonobject p = prefobject .getjsonobject(i); } }
Comments
Post a Comment