我有这段代码:
<?php
$fql = "SELECT url, normalized_url, share_count, like_count, comment_count, ";
$fql .= "total_count, commentsbox_count, comments_fbid, click_count FROM ";
$fql .= "link_stat WHERE url = 'http://apple.com'";
$apifql = "https://api.facebook.com/method/fql.query?format=json&query=".urlencode($fql);
$json = file_get_contents($apifql);
$obj = json_decode($json);
print_r($obj);
?>
输出:
Array ( [0] => stdClass Object ( [url] => http://apple.com [normalized_url] => http://www.apple.com/ [share_count] => 366493 [like_count] => 514795 [comment_count] => 298452 [total_count] => 1179740 [commentsbox_count] => 0 [comments_fbid] => 381975869314 [click_count] => 16558 ) )
如何仅将commentsbox_count
定义为字符串?我需要它用于我的数据库。
答案 0 :(得分:1)
您可以通过$obj[0]->commentsbox_count
访问它。
顶级元素是一个单元素数组,唯一的键是0
。此元素是一个stdClass对象(它非常类似于数组,但具有属性而不是数组元素),因此您可以使用->name
访问该元素。