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

I need to get information from JSON in PHP

这是以下结果: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但是我什么也没有。

您需要先在字符串的两侧使用 {} 来制作此 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,让我知道它是否适合你。