php json_encode只支持utf-8編碼,自定義一個函數便可解決之: php
public function my_json_encode(array $data) {
$s= array();
foreach($data as $k => $v) {
if(is_array($v)) {
$v = my_json_encode($v);
$s[] = "\"$k\":$v";
}else{
$v = addslashes( str_replace( array("\n","\r"), '', $v));
$s[] = "\"$k\": \"$v\"";
}
}
return '{'.implode(', ', $s).'}';
} json