我需要从PHP中获取JSON的信息

时间:2016-05-29 12:55:43

标签: php json yelp

以下是结果:var_dump($response)

"is_claimed": false, "rating": 4.5, "mobile_url": "http://m.yelp.com/biz/filbert-steps-san-francisco?utm_campaign=yelp_api\u0026utm_medium=api_v2_business\u0026utm_source=NUQkLT4j4VnC6ZR7LI-VWA", "rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png", "review_count": 208

我想获得评分值,我试过$response->rating但我什么也没得到。

1 个答案:

答案 0 :(得分:1)

你需要首先在字符串的两边使用{}来创建这个json。解码后(json_decode)你会得到一个对象数组。

$json = '{"is_claimed": false, "rating": 4.5, "mobile_url": "http://m.yelp.com/biz/filbert-steps-san-francisco?utm_campaign=yelp_api\\u0026utm_medium=api_v2_business\\u0026utm_source=NUQkLT4j4VnC6ZR7LI-VWA", "rating_img_url": "https://s3-media2.fl.yelpcdn.com/assets/2/www/img/99493c12711e/ico/stars/v1/stars_4_half.png", "review_count": 208}';
$result = json_decode ($json);

echo $result->rating; // 4.5

Online Check,让我知道它是否适合你。