JSON Parsing Example
try {
JSONObject reader = new JSONObject(response);
JSONArray arr_ob = reader.getJSONArray("categories");
for (int i = 0; i < arr_ob.length(); i++) {
JSONObject for_cat_ob = arr_ob.getJSONObject(i);
String cat_name = for_cat_ob.getString("cat_name");
Log.d("peh19", " " + cat_name);
}
Category_name = reader.getString("cat_name");
// Category_image = reader.getString("cat_image");
Log.d("abc12", Category_name + "");
// Log.d("abc", Category_image + "");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Log.d("5jan", e.toString() + " I catched");
}
} catch (Exception e) {
Log.d("16test", e.toString());
}
}
{
"categories": [
{
"cat_id": "99",
"cat_name": "Smart Phones",
"cat_image": "http://www.crazzybazaar.com/Bussiness_user/shoplogo/312590apple.png",
"products": [
{
"p_id": "187",
"p_name": "Panasonic P31",
"p_image": "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_5137337201433255PM_635_panasonic_p31.jpeg",
"p_mrp_price": "11490",
"p_discount": "39%",
"p_price": "6990"
},
{
"p_id": "186",
"p_name": "Micromax A177 Canvas Juice",
"p_image": "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_318162321201412001PM_635_micromax_canvas_juice_a177.jpeg",
"p_mrp_price": "9999",
"p_discount": "38%",
"p_price": "6190"
},
{
"p_id": "185",
"p_name": "Gionee Pioneer P3",
"p_image": "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_424142679290223154018158501654882165484016547841353714p2side13821784711383385287138736474713873656261387365852138917517213922782511395644013.png",
"p_mrp_price": "7549",
"p_discount": "15%",
"p_price": "6449"
}
]
},
{
"cat_id": "100",
"cat_name": "Cell Phones",
"cat_image": "http://www.crazzybazaar.com/Bussiness_user/shoplogo/42320mobile178.png",
"products": [
{
"p_id": "195",
"p_name": "Spice Boss Rhythm M-5367",
"p_image": "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_138590spicebossrhythmm5367mobilephoneblackmediumff1e25974bbcba9bcadbc1c0442b41c21391593374.jpg",
"p_mrp_price": "1560",
"p_discount": "18%",
"p_price": "1275"
},
{
"p_id": "194",
"p_name": "Spice Mi-300",
"p_image": "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_4985085302013103651AM_635_spice_mi_300.png",
"p_mrp_price": "2650",
"p_discount": "9%",
"p_price": "2400"
},
{
"p_id": "193",
"p_name": "Gionee L700",
"p_image": "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_310664Gionee L700.jpg",
"p_mrp_price": "1995",
"p_discount": "10%",
"p_price": "1799"
}
]
}
]
}