您好,欢迎访问一九零五行业门户网

PHP如何让json_encode不转义中文?

php如何让json_encode不转义中文?
php让json_encode不转义中文的方法:在使用“json_encode()”函数进行json编码时,在第2个参数传入常量“json_unescaped_unicode”,其意义是以字面编码多字节unicode字符。
代码示例
$jsonstr = json_encode($data,json_unescaped_unicode);
json 预定义常量
json_error_none (integer)
没有错误发生。自 php 5.3.0 起生效。
json_error_depth (integer)
到达了最大堆栈深度。自 php 5.3.0 起生效。
json_error_state_mismatch (integer)
出现了下溢(underflow)或者模式不匹配。自 php 5.3.0 起生效。
json_error_ctrl_char (integer)
控制字符错误,可能是编码不对。自 php 5.3.0 起生效。
json_error_syntax (integer)
语法错误。 自 php 5.3.0 起生效。
json_error_utf8 (integer)
异常的 utf-8 字符,也许是因为不正确的编码。 自 php 5.3.3 起生效。
json_error_recursion (integer)
the object or array passed to json_encode() include recursive references and cannot be encoded. if the json_partial_output_on_error option was given, null will be encoded in the place of the recursive reference. available since php 5.5.0.
json_error_inf_or_nan (integer)
the value passed to json_encode() includes either nan or inf. if the json_partial_output_on_error option was given, 0 will be encoded in the place of these special numbers. available since php 5.5.0.
json_error_unsupported_type (integer)
a value of an unsupported type was given to json_encode(), such as a resource. if the json_partial_output_on_error option was given, null will be encoded in the place of the unsupported value. available since php 5.5.0.
json_error_invalid_property_name (integer)
a key starting with \u0000 character was in the string passed to json_decode() when decoding a json object into a php object. available since php 7.0.0.
json_error_utf16 (integer)
single unpaired utf-16 surrogate in unicode escape contained in the json string passed to json_encode(). available since php 7.0.0.
下面的常量可以和 json_decode() 的 form 选项结合使用。
json_bigint_as_string (integer)
将大数字编码成原始字符原来的值。 自 php 5.4.0 起生效。
json_object_as_array (integer)
decodes json objects as php array. this option can be added automatically by calling json_decode() with the second parameter equal to true. available since php 5.4.0.
下面的常量可以和 json_encode() 的 form 选项结合使用。
json_hex_tag (integer)
所有的 92d33664ec5f827b86e068a341370a86 转换成 \u003c 和 \u003e。 自 php 5.3.0 起生效。
json_hex_amp (integer)
所有的 & 转换成 \u0026。 自 php 5.3.0 起生效。
json_hex_apos (integer)
所有的 ' 转换成 \u0027。 自 php 5.3.0 起生效。
json_hex_quot (integer)
所有的 转换成 \u0022。 自 php 5.3.0 起生效。
json_force_object (integer)
使一个非关联数组输出一个类(object)而非数组。 在数组为空而接受者需要一个类(object)的时候尤其有用。 自 php 5.3.0 起生效。
json_numeric_check (integer)
将所有数字字符串编码成数字(numbers)。 自 php 5.3.3 起生效。
json_pretty_print (integer)
用空白字符格式化返回的数据。 自 php 5.4.0 起生效。
json_unescaped_slashes (integer)
不要编码 /。 自 php 5.4.0 起生效。
json_unescaped_unicode (integer)
以字面编码多字节 unicode 字符(默认是编码成 \uxxxx)。 自 php 5.4.0 起生效。
json_partial_output_on_error (integer)
substitute some unencodable values instead of failing. available since php 5.5.0.
json_preserve_zero_fraction (integer)
ensures that float values are always encoded as a float value. available since php 5.6.6.
json_unescaped_line_terminators (integer)
the line terminators are kept unescaped when json_unescaped_unicode is supplied. it uses the same behaviour as it was before php 7.1 without this constant. available since php 7.1.0.
推荐教程:《php》
以上就是php如何让json_encode不转义中文?的详细内容。
其它类似信息

推荐信息