PHP中通过json_解码数组的Foreach循环
我试图通过数组foreach循环,但遇到了麻烦,我得到了“未定义的索引:文本” 代码如下: $tweets=json_decode($response,true) foreach($tweets作为$tweet){ } JSON数据如下所示: 对象(stdClass)[2]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['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) {