踩坑Json_encode

We know when to use PHP's json_encode to handle Chinese, the Chinese will be encoded into unreadable, similar to the "\ u ***" format, will also increase the amount of data transmitted to a certain extent.

<? PHP
echo json_encode ( "Chinese");
 
// "\ u4E2D \ u6587"
?>
This allows us to do to develop these students, it is a headache, and sometimes had to write their own json_encode.

In PHP5.4, the issue was finally resolved, Json new option: JSON_UNESCAPED_UNICODE, named Incredibles, that is to say, Json do not encode Unicode.
See the examples below:

<?php
echo json_encode("中文", JSON_UNESCAPED_UNICODE);
 
//"中文"
?>

Json 5.4 also added: JSON_BIGINT_AS_STRING, JSON_PRETTY_PRINT, JSON_UNESCAPED_SLASHES other options,

If you are interested, you can see: https://www.php.net/manual/en/function.json-encode.php

Guess you like

Origin blog.csdn.net/liuzhidan123__/article/details/91411633