我正在尝试处理来自 facebook 图表的帖子消息。
https://graph.facebook.com/comments/?ids=http://www.myawesomedomain.com/post_nr38.html
结果是:
{
"http://www.myawesomedomain.com/post_nr38.html": {
"comments": {
"data": [
{
"id": "123381557832360_139652",
"from": {
"name": "Zbarcea Ioan-Christian",
"id": "100001004884254"
},
"message": "test 3",
"can_remove": false,
"created_time": "2013-08-30T14:44:51+0000",
"like_count": 0,
"user_likes": false
},
{
"id": "123381557832360_139651",
"from": {
"name": "Zbarcea Ioan-Christian",
"id": "100001004884254"
},
"message": "test 2",
"can_remove": false,
"created_time": "2013-08-30T14:28:16+0000",
"like_count": 0,
"user_likes": false
},
{
"id": "123381557832360_139650",
"from": {
"name": "Zbarcea Ioan-Christian",
"id": "100001004884254"
},
"message": "test 1",
"can_remove": false,
"created_time": "2013-08-30T14:28:12+0000",
"like_count": 0,
"user_likes": false
}
],
"paging": {
"cursors": {
"after": "MQ==",
"before": "Mw=="
}
}
}
}
}
编码:
$html = file_get_contents('https://graph.facebook.com/comments/?ids=http://www.myawesomedomain.com/post_nr38.html');
$json_data = json_decode($html);
foreach ($json_data as $data)
{
echo "Name: ".$data['name']."<br />Message: ".$data['message'];
}
但它是空的,没有给出输出。我知道这与循环有关。我从来没有使用过 JSON。