您好我一直试图以JSON格式提取数据。这是我的代码
$resourse_url = 'http://www.livepicly.com/app/api.php?method=list_vendor_name';
$json_data = file_get_contents($resourse_url);
$json_output = json_decode($json_data, TRUE);
$vendor = $json_output['vendor_name'][1];
echo "<pre>";
print_r($vendor);
exit(1);
然而,当我运行代码时,它不会返回任何内容。当我尝试通过firefox访问源URL时,它会询问我将JSON数据保存为* .php的位置,但是当我从Chrome访问源URL时,它会正常显示JSON数据。
我该怎么办?有谁能指出我的解决方案? THX
答案 0 :(得分:0)
在http://jsonformatter.curiousconcept.com/
上运行返回的json{
"result":[
{
"vendor_id":"726",
"vendor_name":"Scusa"
},
{
"vendor_id":"519",
"vendor_name":"Emilie French Restaurant and Bar"
},
{
"vendor_id":"482",
"vendor_name":"Cassis French Fine Dining"
},
{
"vendor_id":"435",
"vendor_name":"Asuka Japanase Dining"
},
{
"vendor_id":"12050",
"vendor_name":"Taipan"
},
{
"vendor_id":"12061",
"vendor_name":"Social House"
},
{
"vendor_id":"12103",
"vendor_name":"Harum Manis Indonesian Restaurant"
},
{
"vendor_id":"12193",
"vendor_name":"Nanny\'s Pavillion (Central Park)"
},
{
"vendor_id":"12272",
"vendor_name":"Bistro Baron"
},
{
"vendor_id":"20704",
"vendor_name":"Kitchenette (Central Park)"
},
{
"vendor_id":"21217",
"vendor_name":"Kitchenette (Plaza Indonesia)"
},
{
"vendor_id":"29859",
"vendor_name":"Momento Restaurant And Bar"
},
{
"vendor_id":"31055",
"vendor_name":"Tortuga Kitchen And Bar"
},
{
"vendor_id":"31056",
"vendor_name":"Tuck And Chug"
},
{
"vendor_id":"31060",
"vendor_name":"AUROZ Gourmet Grill"
}
]
}
它在此行找到了无效字符
"vendor_name":"Nanny\'s Pavillion (Central Park)"