vijay
1/27/2015 - 11:02 AM

JSON_Example_2

JSON_Example_2

{
    "total_reviews": 2,
    "reviews": [
        {
            "review_id": "32",
            "shop_name": "Saviyo The Mobile Megastore",
            "shop_image": "http://www.crazzybazaar.com/Bussiness_user/shoplogo/292504mobile-show-room.jpg2_.jpg",
            "review_date": null,
            "type_of_visit": "friends_hangout",
            "type_of_visit_image": "http://www.crazzybazaar.com/images/friends_hangout.jpg",
            "total_rating": "8.9",
            "product_rating": "7.925",
            "quality_rating": "10",
            "services_rating": "8.825",
            "user_image": "http://www.crazzybazaar.com/Bussiness_user/user_images/no_image.jpg",
            "user_name": "Bhagwat pandya",
            "likes": 2,
            "user_like": 0,
            "dislikes": 0,
            "user_dislike": 0,
            "greatfuls": 1,
            "user_greatful": 0,
            "comment_counts": 0,
            "comments": [
                {
                    "user_image": "",
                    "user_name": "",
                    "comment": "",
                    "comment_date": ""
                }
            ]
        },
        {
            "review_id": "30",
            "shop_name": "Saviyo The Mobile Megastore",
            "shop_image": "http://www.crazzybazaar.com/Bussiness_user/shoplogo/292504mobile-show-room.jpg2_.jpg",
            "review_date": null,
            "type_of_visit": "solo_peace",
            "type_of_visit_image": "http://www.crazzybazaar.com/images/solo_peace.jpg",
            "total_rating": "8",
            "product_rating": "8.025",
            "quality_rating": "6.975",
            "services_rating": "8.975",
            "user_image": "http://www.crazzybazaar.com/Bussiness_user/user_images/258760wb051078.jpg",
            "user_name": "Nitin Gupta",
            "likes": 4,
            "user_like": 1,
            "dislikes": 1,
            "user_dislike": 0,
            "greatfuls": 1,
            "user_greatful": 0,
            "comment_counts": 1,
            "comments": [
                {
                    "user_image": "http://www.crazzybazaar.com/Bussiness_user/user_images/thumb_143634ssshhhheeiikkhh.jpg",
                    "user_name": "Sheikh Mohd Hakim",
                    "comment": "nice",
                    "comment_date": "on Jan 08, 2015, 12:00 AM"
                }
            ]
        }
    ]
}
	try {
				JSONObject jsonObject = new JSONObject(response);

				String total_reviews = jsonObject.getString("total_reviews");

				Log.d("mytest27", total_reviews + "");

				JSONArray json_arr = jsonObject.getJSONArray("reviews");

				for (int i = 0; i < json_arr.length(); i++) {
					JSONObject reviews_ob = json_arr.getJSONObject(i);
					String review_id = reviews_ob.getString("review_id");

					String shop_name = reviews_ob.getString("shop_name");

					String shop_image = reviews_ob.getString("shop_image");

					String review_date = reviews_ob.getString("review_date");

					String type_of_visit = reviews_ob
							.getString("type_of_visit");

					String type_of_visit_image = reviews_ob
							.getString("type_of_visit_image");

					String total_rating = reviews_ob.getString("total_rating");

					String quality_rating = reviews_ob
							.getString("quality_rating");

					String services_rating = reviews_ob
							.getString("services_rating");

					String user_image = reviews_ob.getString("user_image");

					String user_name = reviews_ob.getString("user_name");

					String likes = reviews_ob.getString("likes");

					String user_like = reviews_ob.getString("user_like");

					String dislikes = reviews_ob.getString("dislikes");

					String user_dislike = reviews_ob.getString("user_dislike");

					String greatfuls = reviews_ob.getString("greatfuls");

					String user_greatful = reviews_ob
							.getString("user_greatful");

					String comment_counts = reviews_ob
							.getString("comment_counts");

					// fetching data form comments_json_array

					JSONArray comments_json_array = reviews_ob
							.getJSONArray("comments");

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

						JSONObject comments_json_array_json_object = comments_json_array
								.getJSONObject(j);

						Log.d("mytest27", comments_json_array_json_object
								.getString("user_image"));

						Log.d("mytest27", comments_json_array_json_object
								.getString("user_name"));

						Log.d("mytest27", comments_json_array_json_object
								.getString("comment"));

						Log.d("mytest27", comments_json_array_json_object
								.getString("comment_date"));

					}

					Log.d("mytest27", shop_name + "<-->" + shop_image + "<-->"
							+ review_date + "<--> " + type_of_visit + "<-->"
							+ type_of_visit_image + "<-->" + total_rating
							+ "<-->" + quality_rating + "<-->"
							+ services_rating + "<-->" + user_image + "<-->"
							+ user_name + "<-->" + user_image + "<-->"
							+ user_name + "<-->" + likes + "<-->" + user_like
							+ "<-->" + dislikes + "<-->" + comment_counts);
				}

			} catch (JSONException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();

				Log.d("mytest27", e.toString());
			}

		}