Phpjson_encode always returns the unicode character u. solve the problem recently encountered a strange problem. The code written two days ago is garbled again today. Check whether the returned unicode characters are not garbled characters in general sense.
For example, Chinese characters: logon failed. after json_encode is passed, the returned result is: "\ u767b \ u5f55 \ u5931 \ u8d25"
I found it a common problem and finally solved it as follows:
Call json_encode ($ arr) normally, and process the json data between echo using the following function:
Public static function JSON ($ str ){
$ Json = json_encode ($ str );
Return preg_replace ("# \\\ u ([0-9a-f] +) # ie", "iconv ('ucos-2', 'utf-8', pack ('h4 ', '\ 1') ", $ json );
}
In this way, there will be no garbled characters. For php of a later version, you can add a parameter directly, but it is invalid for a later version. The complete code is as follows:
Call example:
// Echo "logon failed"; $ arr = array (); $ arr ['code'] =-1; $ arr ['message'] = "logon failed "; echo $ arr ['message']; $ arr ['data'] = ""; return util: JSON ($ arr );
Reference: http://stackoverflow.com/questions/6771938/any-way-to-return-php-json-encode-with-encode-utf-8-and-not-unicode