This article mainly introduces the PHP implementation Json_decode does not escape the Chinese method, combined with the case-specific analysis of the php5.4+ and 5.3 version of the implementation of the Json_decode to achieve non-escaping Chinese specific operating skills and related considerations, the need for friends can refer to the following
Specific as follows:
By default, PHP's Json_decode method escapes special characters and also turns Chinese into Unicode
encoded form.
This makes it cumbersome to view the text in a database. So we need to limit the escape to Chinese.
For the php5.4+ version, the Json_decode function is the second parameter that can be used to limit the escape range.
To restrict Chinese, use JSON_UNESCAPED_UNICODE
parameters.
Json_encode ($a, json_unescaped_unicode);
For the PHP5.3 version, you can first convert more than ASCII 127 characters to HTML values to avoid being transcoded by the Json_decode function:
function My_json_encode ($arr) { //convmap since 0x80 char codes so it takes all multibyte codes (above ASCII 127). So such characters is being "hidden" from normal json_encoding array_walk_recursive ($arr, function (& $item, $key {if (is_string ($item)) $item = Mb_encode_numericentity ($item, Array (0x80, 0xFFFF, 0, 0xFFFF), ' UTF-8 ');}); Return mb_decode_numericentity (Json_encode ($arr), Array (0x80, 0xFFFF, 0, 0xFFFF), ' UTF-8 ');}
Related recommendations:
How PHP implements the app interface and returns JSON data
Getjson () Asynchronous Request server returns JSON formatted data (tutorial)
A detailed description of JSON object definition and value implementation in JS