0

有人可以告诉我如何遍历下面的数组吗?

http://pastebin.com/rhaF5Zdi

我试过没有运气:

$_data = json_decode($_data);
foreach ( $_data as $tweet )
{
    echo "{$tweet->text}\n";
}

谢谢

ps:我正在关注这个 php 脚本。 http://mikepultz.com/2013/06/mining-twitter-api-v1-1-streams-from-php-with-oauth/

她在阵列上的另一个粘贴箱。似乎有多个数组发生 http://pastebin.com/dduzhpqY

4

3 回答 3

1

看起来您可能正在创建 PHP stnd 对象而不是数组

//this will create a php standard object
$objOfData=json_decode($json); 

而是使用以下版本:(注意第二个参数是 TRUE

$associativeArray=json_decode($json, TRUE); 

这会将对象转换为关联数组,您可以像这样访问字段:

$id=$associativeArray['id'];

更多信息:json_decode

于 2013-09-26T01:08:56.090 回答
0

发布链接中的代码不是 JSON,而是 print_r() 函数的输出。PHP 没有 print_r() 的反转函数,但在 php.net 上的 print_r() 文档注释中,您可以找到一些可以读取它的用户自定义函数。

例如这个: http ://www.php.net/manual/en/function.print-r.php#93529

我希望它会有所帮助。祝你好运 :)

于 2013-09-26T01:48:32.750 回答
0

最终使用:

if(array_key_exists('text', $_data)){
        echo 'Tweet ID = '.$_data['id_str'];
        echo 'Tweet Text = '.$_data['text'];
        echo '<br /><br />';
    }

干杯

于 2013-09-26T04:36:02.163 回答