从 Twitter 搜索 API 解析 trends.json

发布于 2024-11-04 17:55:04 字数 1675 浏览 1 评论 0原文

正在努力解析来自 http://api.twitter.com/1/trends/ 的 JSON 响应current.json

使用 foreach ($json_output->trends[0] as $trend ) { echo $趋势->名称; }

stdClass Object ( [trends] => stdClass Object ( [2011-05-03 17:43:42] => Array ( [0] => stdClass Object ( [query] => TeAmamosLuanS [events] => [promoted_content] => [name] => TeAmamosLuanS ) [1] => stdClass Object ( [query] => CASEY RULES [events] => [promoted_content] => [name] => CASEY RULES ) [2] => stdClass Object ( [query] => Rashard Mendenhall [events] => [promoted_content] => [name] => Rashard Mendenhall ) [3] => stdClass Object ( [query] => Alexandre Nardoni [events] => [promoted_content] => [name] => Alexandre Nardoni ) [4] => stdClass Object ( [query] => Henrique Capriles [events] => [promoted_content] => [name] => Henrique Capriles ) [5] => stdClass Object ( [query] => LivroRestart [events] => [promoted_content] => [name] => LivroRestart ) [6] => stdClass Object ( [query] => TeamXtina [events] => [promoted_content] => [name] => TeamXtina ) [7] => stdClass Object ( [query] => Howard Webb [events] => [promoted_content] => [name] => Howard Webb ) [8] => stdClass Object ( [query] => Camp Nou [events] => [promoted_content] => [name] => Camp Nou ) [9] => stdClass Object ( [query] => MTV Movie Awards [events] => [promoted_content] => [name] => MTV Movie Awards ) ) ) [as_of] => 1304444622 ) 

请帮助数组/对象解析。谢谢。

Struggling to parse this JSON response from http://api.twitter.com/1/trends/current.json

using foreach ($json_output->trends[0] as $trend )
{
echo $trend->name;
}

stdClass Object ( [trends] => stdClass Object ( [2011-05-03 17:43:42] => Array ( [0] => stdClass Object ( [query] => TeAmamosLuanS [events] => [promoted_content] => [name] => TeAmamosLuanS ) [1] => stdClass Object ( [query] => CASEY RULES [events] => [promoted_content] => [name] => CASEY RULES ) [2] => stdClass Object ( [query] => Rashard Mendenhall [events] => [promoted_content] => [name] => Rashard Mendenhall ) [3] => stdClass Object ( [query] => Alexandre Nardoni [events] => [promoted_content] => [name] => Alexandre Nardoni ) [4] => stdClass Object ( [query] => Henrique Capriles [events] => [promoted_content] => [name] => Henrique Capriles ) [5] => stdClass Object ( [query] => LivroRestart [events] => [promoted_content] => [name] => LivroRestart ) [6] => stdClass Object ( [query] => TeamXtina [events] => [promoted_content] => [name] => TeamXtina ) [7] => stdClass Object ( [query] => Howard Webb [events] => [promoted_content] => [name] => Howard Webb ) [8] => stdClass Object ( [query] => Camp Nou [events] => [promoted_content] => [name] => Camp Nou ) [9] => stdClass Object ( [query] => MTV Movie Awards [events] => [promoted_content] => [name] => MTV Movie Awards ) ) ) [as_of] => 1304444622 ) 

Please help with array/object parsing. Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

稀香 2024-11-11 17:55:04

你可以使用类似的东西:

<?php
$json_output = json_decode(file_get_contents("http://api.twitter.com/1/trends/current.json"));
foreach ($json_output->trends as $datetime=>$vals ) {
    echo "As of $datetime the trends are:<br />";
    echo "<ul>";
    foreach($vals as $trend)
        echo "<li>{$trend->name}</li>";
    echo "</ul>";
}
?>

输出:

截至2011-05-03 22:07:58 趋势
是:

  • #onethingiveneverdone
  • #开启
  • #pssst
  • 伊恩·布鲁
  • 贾斯汀·比伯伦
  • 可怜的梅西
  • 德里克·罗斯 MVP
  • 仙妮亚·唐恩
  • 拉沙德·门登霍尔
  • 拉丁语BeliebersASKDates

You could use something like:

<?php
$json_output = json_decode(file_get_contents("http://api.twitter.com/1/trends/current.json"));
foreach ($json_output->trends as $datetime=>$vals ) {
    echo "As of $datetime the trends are:<br />";
    echo "<ul>";
    foreach($vals as $trend)
        echo "<li>{$trend->name}</li>";
    echo "</ul>";
}
?>

Output:

As of 2011-05-03 22:07:58 the trends
are:

  • #onethingiveneverdone
  • #turnon
  • #pssst
  • Irn Bru
  • Justin Bieberon
  • Pobre Messi
  • Derrick Rose MVP
  • Shania Twain
  • Rashard Mendenhall
  • LatinBeliebersASKDates
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文