duanlu0075 2013-01-30 21:25
浏览 27

来自数组的回声数据[关闭]

I am currently calling Twitter's "Trending" API with PHP and I want to return the top 10 trending topics. Currently it appears to be echoed into an array but I can't work out how to get an individual piece of data on it's one.

I want to just return the name attribute for each one. How can I do this?

My existing code is:

<?

$search=file_get_contents("https://api.twitter.com/1/trends/1.json");
print_r(json_decode($search));

?>

Decoded array:

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] => 
                        )
                       //...
  • 写回答

1条回答 默认 最新

  • dongzhi4239 2013-01-30 21:29
    关注

    I would assume that json_decode returns an associative array. You could get the value of the name by doing this:

    <?
    
    $search=file_get_contents("https://api.twitter.com/1/trends/1.json");
    $trends = json_decode($search);
    foreach ($trends[0]->trends as $trend){
        echo $trend->name . "<br/>";
    }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用