Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
UTF8用PHP json_encode编码的原因是什么_Php_Json - Fatal编程技术网

UTF8用PHP json_encode编码的原因是什么

UTF8用PHP json_encode编码的原因是什么,php,json,Php,Json,在PHP中,默认情况下json_编码将UTF8字符编码为十六进制实体,例如 $c = json_encode("中"); // return "\u4e2d" 当然,您可以使用JSON\u UNESCAPED\u UNICODE来更改行为 $c = json_encode("中", JSON_UNESCAPED_UNICODE); // return "中" 为什么会出现这种默认情况?因为php的作者就是这么决定的-我不确定您希望得到什么样的答案?请随时提出问题/功能请求~

在PHP中,默认情况下json_编码将UTF8字符编码为十六进制实体,例如

$c = json_encode("中"); // return "\u4e2d"
当然,您可以使用
JSON\u UNESCAPED\u UNICODE
来更改行为

$c = json_encode("中", JSON_UNESCAPED_UNICODE); // return "中"

为什么会出现这种默认情况?

因为php的作者就是这么决定的-我不确定您希望得到什么样的答案?请随时提出问题/功能请求~