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).'}';
}
echo "<br/>";
$a = '汉语怎么';
echo json_encode($a);
$a = iconv('UTF-8', 'gbk', $a);
echo my_json_encode(array($a));
php 的json_encode与json_decode只支持utf-8的编码.json后,汉字会转成unicode,上面函数是支持GBK的编码!
http://zhangxugg-163-com.iteye.com/blog/1883684