我目前正在使用 PHP 调用 Twitter 的“Trending”API,我想返回前 10 个热门话题。目前,它似乎被回显到一个数组中,但我无法弄清楚如何获取一个单独的数据。
我只想返回name
每个属性。我怎样才能做到这一点?
我现有的代码是:
<?
$search=file_get_contents("https://api.twitter.com/1/trends/1.json");
print_r(json_decode($search));
?>
解码数组:
Array
(
[0] => stdClass Object
(
[trends] => Array
(
[0] => stdClass Object
(
[name] => #EuroclubSoloEnEuropaFM
[url] => http://twitter.com/search?q=%23EuroclubSoloEnEuropaFM
[promoted_content] =>
[query] => %23EuroclubSoloEnEuropaFM
[events] =>
)
[1] => stdClass Object
(
[name] => #NBABands
[url] => http://twitter.com/search?q=%23NBABands
[promoted_content] =>
[query] => %23NBABands
[events] =>
)
//...