Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中通过json_解码数组的Foreach循环_Php_Json_Twitter_Foreach - Fatal编程技术网

PHP中通过json_解码数组的Foreach循环

PHP中通过json_解码数组的Foreach循环,php,json,twitter,foreach,Php,Json,Twitter,Foreach,我试图通过数组foreach循环,但遇到了麻烦,我得到了“未定义的索引:文本” 代码如下: $tweets=json_decode($response,true) foreach($tweets作为$tweet){ } JSON数据如下所示: 对象(stdClass)[2] 当需要在状态上循环时,您正在外部对象上循环: foreach ($tweets['statuses'] as $tweet) { 您有两个问题“status”是数组sojson\u decode($response->s

我试图通过数组foreach循环,但遇到了麻烦,我得到了“未定义的索引:文本”

代码如下:

$tweets=json_decode($response,true)

foreach($tweets作为$tweet){

}

JSON数据如下所示:

对象(stdClass)[2]


当需要在状态上循环时,您正在外部对象上循环:

 foreach ($tweets['statuses'] as $tweet) {

您有两个问题“status”是数组so
json\u decode($response->status,true)和文本是对象的属性,所以
echo$tweet->text

这让我“尝试获取非对象的属性”,而“true”则生成$tweets和关联数组
 public 'statuses' => 

  array (size=15)

  0 => 

   object(stdClass)[3]

     public 'metadata' => 

       object(stdClass)[4]

         ...

     public 'created_at' => string 'Mon Aug 04 21:25:41 +0000 2014' (length=30)

     public 'id' => float 4.9640664406701E+17

     public 'id_str' => string '496406644067012608' (length=18)

     public 'text' => string 'Youth is served (in big helpings): 14 Chiefs could >feature NFLs youngest OL..  #Chiefs #NFL' (length=91)
 foreach ($tweets['statuses'] as $tweet) {