1.json_encode()中文在gbk/gb2312中中文返回为null
代码如下 | |||||||||
$arr = array (
array (
'catid' => '4', 'catname' => 'www.111cn.net',
'meta_title' => '一聚教程网2' ) 结果 [{"catid":"4","catname":"www.111cn.net","meta_title":null}] |
Step2
The background PHP page (the page is encoded as UTF-8 or the characters have been converted to UTF-8) uses json_encode to convert the array array in PHP into a JSON string. For example:
代码如下 | |
$testJSON=array(‘name’=>’中文字符串’,’value’=>’test’); echo json_encode($testJSON); ?> 查看输出结果为: {“name”:”u4e2du6587u5b57u7b26u4e32″,”value”:”test”} |
It can be seen that even if UTF8-encoded characters are used, Chinese garbled characters appear when using json_encode. The solution is to process the characters with the function urlencode() before using json_encode, then json_encode, and use the function urldecode() to convert them back when outputting the result. The details are as follows:
The code is as follows | |||||
$testJSON=array(‘name’=>’Chinese string’,’value’=>’test’);
View the output result:
{"name":"Chinese characters string","value":"test"} |
json_encode in php gbk/gb2312 Chinese garbled code 1.json_encode() Chinese in gbk/gb2312 Chinese return is null code As follows $arr = array ( array ( 'catid' = '4', 'catname' = 'www.111cn.net', 'm...