Php 从yelpapi获取数据

Php 从yelpapi获取数据,php,yelp,Php,Yelp,我开始研究YelpAPI。当我发送一个搜索请求时,我得到一个数组$response中返回的数据。所以如果我像这样输出它 echo '<pre>'; print_r($response); echo '</pre>'; 那么,假设我想获取国家代码,难道我不能用类似的东西获取吗 echo $response->businesses[0]->country_code; 我没有得到任何结果。我错过了什么 $response = json_decode(..., t

我开始研究YelpAPI。当我发送一个搜索请求时,我得到一个数组$response中返回的数据。所以如果我像这样输出它

echo '<pre>';
print_r($response);
echo '</pre>';
那么,假设我想获取国家代码,难道我不能用类似的东西获取吗

echo $response->businesses[0]->country_code;
我没有得到任何结果。我错过了什么

$response = json_decode(..., true);
业务
是一个属性,而不是数组元素

stdClass对象
下面的所有内容都是属性

数组
=>下面的所有内容都是数组元素

让我猜猜,
$response=json_decode(…)

通过设置第二个参数
true
,可以告诉此函数返回关联数组而不是对象:

echo $response['businesses'][0]['country_code'];
然后,值将为


大。。。咖啡,我需要更多的咖啡!我们都知道那种感觉。
$response = json_decode(..., true);
echo $response['businesses'][0]['country_code'];