vijay
3/11/2015 - 7:57 AM

FetchingFromJSON Example

FetchingFromJSON Example

{
    "success": true,
    "msg": {
        "list_name": "vk1",
        "list_id": "47",
        "date_of_purchase": "2015-03-18",
        "product": [
            {
                "id": "113",
                "qty": "10",
                "qty_cat_type": "Tola",
                "name": "Joy Pure Aloe All Purpose Aloe Vera Cream (100 ml) ( JOY ) "
            },
            {
                "id": "112",
                "qty": "4",
                "qty_cat_type": "Grams",
                "name": "Wild Stone Aqua Fresh Deodorant Spray - 200 ml ( Wild Stone ) "
            },
            {
                "id": "111",
                "qty": "3",
                "qty_cat_type": "Kg",
                "name": "Diabetic Care ( Product type ) "
            }
        ]
    }
}

				JSONObject jsonObject = new JSONObject(
						ResponseDefaultUnsavedList);

				JSONObject json_ob_msg = jsonObject.getJSONObject("msg");

				//bhai i add (+ "" ) because something server gives me "null" 
				list_name_from_defaultUnsavedList = json_ob_msg
						.getString("list_name") + "";
				list_id_from_defaultUnsavedList = json_ob_msg
						.getString("list_id") + "";
				date_of_purchase_from_defaultUnsavedList = json_ob_msg
						.getString("date_of_purchase") + "";
				prodcut_from_defaultUnsavedList = json_ob_msg
						.getString("product");

				JSONArray prodcut_from_defaultUnsavedList_jsonArray = json_ob_msg
						.getJSONArray("product");

				for (int i = 0; i < prodcut_from_defaultUnsavedList_jsonArray
						.length(); i++) {
					JSONObject product_list_json_Object = prodcut_from_defaultUnsavedList_jsonArray
							.getJSONObject(i);
					product_list_id = product_list_json_Object.getString("id");
					product_list_qty = product_list_json_Object
							.getString("qty");
					product_list_qty_cat_type = product_list_json_Object
							.getString("qty_cat_type");
					product_list_name = product_list_json_Object
							.getString("name");

				}

			} catch (Exception e) {
				Log.d("ServiceResponse", e.toString());
			}