[英]Can't see JSON data - PHP
I was trying to read simple content from http://ergast.com/api/f1/drivers/kobayashi.json with a PHP file, but I can't see anything. 我试图从http://ergast.com/api/f1/drivers/kobayashi.json中读取带有PHP文件的简单内容,但看不到任何内容。
<?php
$file = file_get_contents('http://ergast.com/api/f1/drivers/vettel.json/');
$data = json_decode($file,true);
echo $data['MRData']['DriverTable']['Drivers']['familyName'];
?>
Edit 1: 编辑1:
<?php
$file = file_get_contents('http://ergast.com/api/f1/drivers/vettel.json');
$data = json_decode($file,true);
echo $file;
echo $data;
echo $data['MRData']['DriverTable']['Drivers']['0']['familyName'];
?>
File is the same, but seems I can't reach file because I can't see anything if I open the file. 文件是相同的,但似乎无法访问文件,因为如果打开文件,我什么也看不到。 :( :(
Remove the slash and after the driver result is coming in array. 删除斜杠,并在驱动程序结果进入数组之后。
u can check that with print_r debugging option. 您可以使用print_r调试选项进行检查。
$file = file_get_contents('http://ergast.com/api/f1/drivers/vettel.json');
$data = json_decode($file,true);
//echo "<pre>";
//print_r($data);
//echo "</pre>";
echo $data['MRData']['DriverTable']['Drivers'][0]['familyName'];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.