Nadine Nadine - 2 years ago 101
JSON Question

I need to get information from JSON in PHP

Here is the result of:


"is_claimed": false, "rating": 4.5, "mobile_url": "\u0026utm_medium=api_v2_business\u0026utm_source=NUQkLT4j4VnC6ZR7LI-VWA", "rating_img_url": "", "review_count": 208

I want to get the rating value, I tried
but I got nothing.

Answer Source

You need to make this json first by using {} at two sides of the string. After decoding (json_decode) you will got an Array of Objects.

$json = '{"is_claimed": false, "rating": 4.5, "mobile_url": "\\u0026utm_medium=api_v2_business\\u0026utm_source=NUQkLT4j4VnC6ZR7LI-VWA", "rating_img_url": "", "review_count": 208}';
$result = json_decode ($json);

echo $result->rating; // 4.5

Online Check, and let me know is it works for you or not.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download