Rumah >pembangunan bahagian belakang >tutorial php >json_encode()函数为什么不能解析带中文的JSON字符串呢?
这样就有值:
$a = '{ "a":"www", "b":2}';$arr = json_decode($a, true);
$a = '{ "a":"你好", "b":2}';$arr = json_decode($a, true);
json中的中文都被转码了:
$p = array("name"=>"成龙",array("age"=>55,"cur"=>"电影"));$p_json = json_encode($p);echo $p_json."<br>";#{"name":"\u6210\u9f99","0":{"age":55,"cur":"\u7535\u5f71"}}#\u6210\u9f99 => 成龙,#\u7535\u5f71 => 电影print_r(json_decode($p_json));#stdClass Object ( [name] => 成龙 [0] => stdClass Object ( [age] => 55 [cur] => 电影 ) )
json中的中文都被转码了:
PHP code
$p = array("name"=>"成龙",array("age"=>55,"cur"=>"电影"));
$p_json = json_encode($p);
echo $p_json."
";
#{"name":"\u6210\u9f99","0":{"age":55,"cur":"\u7535\u5f71"}}
#\u6210\……
那它也应该能出来东西啊,不能是NULL吧
在你的编辑器中把字符集改为utf-8
文件编码 utf-8 或者 iconv 自己再转
在你的编辑器中把字符集改为utf-8
嗯好了,谢谢啊!
不能解析中文,我设置了utf-8
header("Content-Type: text/html; charset=utf-8");$p = array("name"=>"成龙",array("age"=>55,"cur"=>"电影"));$p_json = json_encode($p);