Monday, May 19, 2014

Json header and encode for PHP

link source: http://stackoverflow.com/questions/4064444/returning-json-from-a-php-script

PHP對JSON編碼後,送回去的資料型態利用header定義好再送回。
$data = array('a'=>array(1,2,3,4,5,6),'b'=>'bcd')/** whatever you're serializing **/;
header('Content-Type: application/json');
echo json_encode($data);

No comments: