使用以下内容,我可以将所有信息显示为两种格式的数组,但是我希望为变量分配一个值并使用例如名称而不是完整的屏幕转储。
$url = 'http://myurl';
$json = file_get_contents($url);
$dump=(var_dump(json_decode($json, true)));
$json_output = json_decode($json); print_r($json_output)
这可能很简单,我很抱歉。
最佳答案
您可以使用:
$object = json_decode($json);
这将创建一个对象,然后您可以访问该对象的属性......
echo $object->whatever;
或者您可以像这样使用 json_decode:
$array = json_decode($json, TRUE);
这将创建一个数组,您可以像这样访问各个键。
echo $array['whatever'];
关于php - 如何显示特定的 json 值而不是打印或转储函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10230595/