我需要解码一个json文件并在页面中显示它。 我的代码不起作用,我不知道什么是错的。 输出只是一个空白页。
这是json文件。。
{
"data": [
{
"name": "Jhaimee",
"uid": 10000
},
{
"name": "Ally",
"uid": 10000133
},
{
"name": "Macers",
"uid": 1000056
},
{
"name": "Diego",
"uid": 100004
},
{
"name": "Killersmile",
"uid": 1000050
},
{
"name": "Joel",
"uid": 1000011
}
]
}
我希望输出为..
Jhaimee
Ally
Macers
Diego
Killersmile
Joel
这是我的php。
$data = file_get_contents("https://graph.facebook.com/fql?q=SELECT name,uid FROM user WHERE uid IN (SELECT recipients FROM thread WHERE folder_id = 0 ORDER BY message_count DESC) AND uid != me() LIMIT 10&access_token=xxxx");
$data = json_decode($data, true);
echo $data[0]["name"];
答案 0 :(得分:3)
最外面的数组键应该是数据
echo $data['data'][0]['name']
foreach($data['data'] as $person){ echo $person['name'] . "<br />\n"; }