屏幕上沒有顯示,這個有效的代碼在下面?我知道在接收到的數據中有一個名爲'text'的JSON參數,但不知道如何將其打印出來?用PHP打印出JSON
<?php
$url='http://twitter.com/statuses/user_timeline/twostepmedia.json'; //rss link for the twitter timeline
//print_r(get_data($url)); //dumps the content, you can manipulate as you wish to
$obj = json_decode($data);
print $obj->{'text'};
/* gets the data from a URL */
function get_data($url)
{
$ch = curl_init();
$timeout = 5;
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
?>
做`的print_r($ OBJ)`看到實際的結構。乍一看,整個json被包裝在一個數組中,所以它可能是`$ obj [0] - > text`。 – mario 2011-01-14 21:27:07
首先看看`$ obj`包含什麼,然後從那裏開始。 – 2011-01-14 21:27:38