我正在使用 Yelp API v1,我正在尝试获取存储在类别对象中的 category_filter。我的 JSON 的一小部分如下所示:
"businesses": [
{
"address1": "800 N Point St",
"phone": "4157492060",
"categories": [{
"category_filter": "newamerican",
"search_url": "http://www.yelp.com/search?cflt=newamerican\u0026find_desc=\u0026find_loc=800+N+Point+St%2C+San+Francisco+94109",
"name": "American (New)"
}],
"name": "Gary Danko",
}]
我的 php 脚本如下所示:
<?php
$yelpstring = file_get_contents("PATH TO JSON", true);
$obj = json_decode($yelpstring, true);
foreach($obj['businesses'] as $business){
echo "Restaurant name: " . $business['name']."<br/>";
echo "Restaurant Type: " . $business['categories']['category_filter']."<br/>";
echo "Address 1: " . $business['address1']."<br/>";
echo "Phone: " . $business['phone'] ."<br/>";
echo "<hr>";
}
?>
我得到了姓名、地址 1 和电话,但不是 category_filter 我得到一个 php 错误,上面写着:
“注意:未定义的索引:第 12 行 file.php 中的 category_filter”
我不明白我做错了什么。