PHP> File_get_contents + json_decode不起作用

时间:2013-01-06 19:22:47

标签: php json file-get-contents

我在使用来自http://api.justin.tv/api/stream/list.json?channel=HerdynJson时遇到问题,我需要获取有关直播的一些信息。 我的代码:

<?php
$json = file_get_contents('http://api.justin.tv/api/stream/list.json?channel=Herdyn');
$obj = json_decode($json);

echo $obj->{'name'};
?>

当我将其上传到服务器上时:http://blx.patrikpapso.com/herdyn/,没有错误,只是空白页,不知道该怎么做......

1 个答案:

答案 0 :(得分:5)

执行var_dump($obj);,您会看到没有属性“名称”。 JSON是一个包含具有此类属性的对象的数组:

$firstObj = $obj[0];
echo $firstObj->name;

甚至

echo $obj[0]->name;

应该至少有一个E_NOTICE。

相关问题