您好我无法取出上面显示的JSON中的文本字段。
$json = json_encode($response);
echo $json;
$decode = json_decode($json, true);
$decode = reset($decode);
$count = count($decode);
echo $count;
for($i=0;$i<$count;$i++){
$latestTweet = htmlentities($json[$i]->text, ENT_QUOTES);
$latestTweet = preg_replace('/http:\/\/([a-z0-9_\.\-\+\&\!\#\~\/\,]+)/i', '<a href="http://$1" target="_blank">http://$1</a>', $latestTweet);
$latestTweet = preg_replace('/@([a-z0-9_]+)/i', '<a href="http://twitter.com/$1" target="_blank">@$1</a>', $latestTweet);
echo $latestTweet;
}
我收到此错误:
Notice: Trying to get property of non-object in C:\Users\Vini\Documents\My Web Sites\twitteroauth-master\test.php on line 79
答案 0 :(得分:0)
json_encode函数接受一个关联数组并返回一个json字符串。您正在尝试将字符串用作对象(使用 - &gt;)。这就是你得到这个错误的原因。 但是json_decode接受一个json字符串并默认返回对象。