20091108

[筆記] PEAR Services JSON

在使用AR Services JSON這支程式時

include '/usr/share/pear/Services/JSON.php';
$data = array('a'=> 1,'b'=>2);
$json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
$cache_data = $json -> encode($data);

但,encode這個function內容是這樣的
function encode($var)
{
header('Content-type: application/json');
return $this->_encode($var);
}
Header會導致 Cannot modify header information - headers already sent by...的錯誤

如果你不要這個Header,用encodeUnsafe()即可解決
$cache_data = $json -> encodeUnsafe($data);

沒有留言: