vijay
1/20/2015 - 7:19 AM

JSON Fetching Example

JSON Fetching Example

{
    "id": "295",
    "name": "LG G3",
    "image": {
        "original": "http://www.crazzybazaar.com/Bussiness_user/productImages/original/277445lg_g3_trio-100271331-large.idge.jpg",
        "small": "http://www.crazzybazaar.com/Bussiness_user/productImages/small/small_277445lg_g3_trio-100271331-large.idge.jpg",
        "thumb": "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_277445lg_g3_trio-100271331-large.idge.jpg"
    },
    "other_images": {
        "original": [
            "http://www.crazzybazaar.com/Bussiness_user/productImages/original/54934LG-G3-2.jpg",
            "http://www.crazzybazaar.com/Bussiness_user/productImages/original/308367LG-G3-3.jpg"
        ],
        "small": [
            "http://www.crazzybazaar.com/Bussiness_user/productImages/small/small_54934LG-G3-2.jpg",
            "http://www.crazzybazaar.com/Bussiness_user/productImages/small/small_308367LG-G3-3.jpg"
        ],
        "thumb": [
            "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_54934LG-G3-2.jpg",
            "http://www.crazzybazaar.com/Bussiness_user/productImages/thumb/thumb_308367LG-G3-3.jpg"
        ]
    },
    "price": "29999",
    "mrp_price": "31000",
    "discount": "3%",
    "no_of_views": "123",
    "brand": "LG",
    "qty": 0,
    "in_stock": 0,
    "variation_type": "",
    "type": "",
    "variations": "",
    "description": "The G3 received mostly positive reviews, with critics praising the overall appearance, performance, display quality, and software of the device. However, several aspects of the G3 were panned, including the company's decision to use a faux metallic plastic instead of actual metal, concerns over the usability of the device due to its large size, and whether the resolution of the display had any real effect on day-to-day usage of the device.",
    "checkout_buttons": 0,
    "specifications": [
        {
            "heading": "Battery",
            "titles": [
                {
                    "title": "Type",
                    "values": "3000 mAh"
                },
                {
                    "title": "Standby Time",
                    "values": "565 hrs"
                },
                {
                    "title": "Talk Time",
                    "values": "19 hrs"
                }
            ]
        },
        {
            "heading": "Other Features",
            "titles": [
                {
                    "title": "SAR Value",
                    "values": "0.39 W/Kg"
                },
                {
                    "title": "SMS Memory",
                    "values": "Yes"
                },
                {
                    "title": "Phone Book Memory",
                    "values": "Yes"
                },
                {
                    "title": "Sensors",
                    "values": "Proximity Sensor, Accelerometer"
                }
            ]
        },
        {
            "heading": "Platform",
            "titles": [
                {
                    "title": "Processor",
                    "values": "Quad-core 2.5 GHz Krait 400"
                },
                {
                    "title": "OS",
                    "values": "Android v4.4.2 (KitKat)"
                }
            ]
        },
        {
            "heading": "Memory and Storage",
            "titles": [
                {
                    "title": "Expandable Memory",
                    "values": "microSD, upto 128 GB"
                },
                {
                    "title": "RAM",
                    "values": "2 GB"
                },
                {
                    "title": "Internal Memory",
                    "values": "16 GB"
                }
            ]
        },
        {
            "heading": "Display and Dimension",
            "titles": [
                {
                    "title": "Dimension size",
                    "values": "146.3 x 74.6 x 8.9 mm"
                },
                {
                    "title": "Weight",
                    "values": "149 g"
                },
                {
                    "title": "Display Size",
                    "values": "5.5 inches"
                },
                {
                    "title": "Resolution",
                    "values": "1440 x 2560 pixels"
                }
            ]
        },
        {
            "heading": "Internet and Connectivity",
            "titles": [
                {
                    "title": "Internet Features",
                    "values": "Email"
                },
                {
                    "title": "Wifi",
                    "values": "Yes"
                },
                {
                    "title": "3G",
                    "values": "Yes"
                },
                {
                    "title": "GPRS",
                    "values": "Yes"
                },
                {
                    "title": "USB Connectivity",
                    "values": "Micro USB, v2"
                },
                {
                    "title": "Audio Jack",
                    "values": "3.5 mm"
                }
            ]
        },
        {
            "heading": "Multimedia",
            "titles": [
                {
                    "title": "FM",
                    "values": "Yes"
                },
                {
                    "title": "Music Player",
                    "values": "Supports HE-AAC, MP3, WMA, GSM FR, AMR-NB, M4A"
                },
                {
                    "title": "Video Player",
                    "values": "Supports AVC, MP4, MPEG4, 3G2, Windows Video, H.264, VC-1, 3GP, H.263"
                }
            ]
        },
        {
            "heading": "Camera",
            "titles": [
                {
                    "title": "Video Recording",
                    "values": "2160p@30fps"
                },
                {
                    "title": "Other Camera Features",
                    "values": "Auto Focus, Flash Support, HDR Mode, Panorama Shots, Face Detection, HD Video Recording, Image Editor, Geo-tagging, Bing Vision, Live Photo Mode"
                },
                {
                    "title": "Flash",
                    "values": "Dual LED"
                },
                {
                    "title": "Secondary Camera",
                    "values": "2.1 Megapixel"
                },
                {
                    "title": "Primary Camera",
                    "values": "13 Megapixel"
                }
            ]
        },
        {
            "heading": "General Features",
            "titles": [
                {
                    "title": "In the Box",
                    "values": "User Guide, Handset, Battery, Charger, Headset, USB Cable"
                },
                {
                    "title": "SIM Type",
                    "values": "Dual Sim, GSM + GSM"
                },
                {
                    "title": "Touch Screen",
                    "values": "Yes"
                },
                {
                    "title": "Call Features",
                    "values": "Conference Call, Speed Dialing, Loudspeaker, Call Divert, Call Timer"
                },
                {
                    "title": "SIM Size",
                    "values": "Nano SIM"
                },
                {
                    "title": "Business Features",
                    "values": "Document Viewer, Document Editor, Pushmail (Microsoft Exchange Active Sync), MS Office"
                }
            ]
        }
    ],
    "seller_info": {
        "shop_id": "375",
        "shop_name": "Sheikh Enterprises",
        "been_here": 2,
        "reviews": 3,
        "products": 17,
        "favorites": 1
    }
}
		try {

				JSONObject reader = new JSONObject(response);

				name = reader.getString("name");
				price = reader.getString("price");
				discount = reader.getString("discount");
				brand = reader.getString("brand");
				qty = reader.getString("qty");
				in_stock = reader.getString("in_stock");
				variation_type = reader.getString("variation_type");
				description = reader.getString("description");
				checkout_buttons = reader.getString("checkout_buttons");
				specifications = reader.getString("specifications");
				seller_info = reader.getString("seller_info");
				image = reader.getString("image");
				other_images = reader.getString("other_images");


				// --------------JSONObject second_level----------------;

				JSONObject second_level = new JSONObject(seller_info);

				shop_id = second_level.getString("shop_id");
				shop_name = second_level.getString("shop_name");
				been_here = second_level.getString("been_here");
				reviews = second_level.getString("reviews");
				products = second_level.getString("products");
				favorites = second_level.getString("favorites");


				// ----------------------------------
				// for getting image
				JSONObject images_level_ob = new JSONObject(image);

				original_single_image = images_level_ob.getString("original");

				Log.d("jan17", original + "");

				// ----------------------------------
				// for getting other images

				JSONObject images_otherimages_ob = new JSONObject(other_images);

				JSONArray images_otherimages_arr = images_otherimages_ob
						.getJSONArray("original");

				Log.d("json17o", images_otherimages_arr + "");

				for (int i = 0; i < images_otherimages_arr.length(); i++) {
					images4productdetail.add(images_otherimages_arr
							.getString(i));
				}

				original = images_level_ob.getString("original");

				Log.d("json2", images4productdetail + "");

				// ----------------------------------------------
				// for fetching specifications
				// first of all i clear the Product_Detail_Desc class main
				// arraylist
				arraylist.clear();

				JSONArray specifications_ob = new JSONArray(specifications);

				for (int i = 0; i < specifications_ob.length(); i++) {

					JSONObject specifications_ob_2 = specifications_ob
							.getJSONObject(i);

					heading_of_product_desc = specifications_ob_2
							.getString("heading");

					heading_of_product_desc_arrlist
							.add(heading_of_product_desc);


					titles_of_product_desc = specifications_ob_2.getString("titles");


					JSONArray titles_of_product_desc_ob = new JSONArray(
							titles_of_product_desc);


					for (int j = 0; j < titles_of_product_desc_ob.length(); j++) {

						JSONObject titles_of_product_desc_json_ob = titles_of_product_desc_ob
								.getJSONObject(j);

						String title_title_of_product_desc = titles_of_product_desc_json_ob
								.getString("title");

						title_of_product_desc_arrlist
								.add(title_title_of_product_desc);

						String value_titles_of_product_desc = titles_of_product_desc_json_ob
								.getString("values");

						value_of_product_desc_arrlist
								.add(value_titles_of_product_desc);

						product_list_hm.put(heading_of_product_desc,
								title_title_of_product_desc);

						// ----------------
						if (j == 0) {
							arraylist.add(new ProductDetailListModel(
											Product_Detail.title_of_product_desc_arrlist
													.get(j),
											Product_Detail.value_of_product_desc_arrlist
													.get(j),
											Product_Detail.heading_of_product_desc_arrlist
													.get(i), (byte) i));
						}


						// ----------------

					}
				}

				// --------------------------------------------

			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				Log.d("5jan", e.toString() + " I catched");
			}