繁体   English   中英

JSON文件(PHP)中的信息获取问题

[英]Problems When Grabbing Information in JSON File (PHP)

因此,我试图从php中的json文件中获取一些数据,该数据应该很简单但无法正常工作

$url = 'http://www.vam.ac.uk/api/json/museumobject';
$contents = array(file_get_contents($url));
var_dump($contents);

这将返回文件的内容。

每当我尝试获取数据时,它都不起作用。

 var_dump($contents[0].records.[0].object);

这将返回整个文件。

任何建议仅在此json文件中返回一条信息的建议: http : //www.vam.ac.uk/api/json/museumobject

尝试JSON解码:

$contents = json_decode(file_get_contents($url));  

// var_dump($contents);

print_r ($contents->records[0]);
print_r ($contents->records[0]->fields);

使用json_decode ,然后传递true,以使其在需要时返回一个关联数组。 资源

$contents = json_decode(file_get_contents($url), true);  
$contents[0]->name

然后,您的$contents将作为数组访问,并且name是您要访问的对象的属性。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM