Php json and arrays support Chinese conversion. Two functions are provided for me in php5. json_encode and json_decode can be used to convert json and arrays, but they cannot be supported in Chinese, the following describes two functions supported by processing a Chinese array. in php5, json_encode and json_decode can implement conversion between json and arrays. However, they do not support Chinese, the following describes a processing function that supports conversion between Chinese arrays and json.
| The code is as follows: |
|
|
/**
* Json generation and analysis support Chinese characters
*/
Class Json_Helper {
/**
* Generate json
*/
Public static function encode ($ str ){
$ Json = json_encode ($ str );
// Linux
Return preg_replace ("# \ u ([0-9a-f] {4}) # ie", "iconv ('ucs-2be ', 'utf-8', pack ('h4 ', '\ 1') ", $ json );
// Windows
// Return preg_replace ("# \ u ([0-9a-f] {4}) # ie", "iconv ('ucs-2le', 'utf-8 ', pack ('h4 ',' \ 1') ", $ json );
}
/**
* Json analysis
*/
Public static function decode ($ str ){
Return json_decode ($ str );
}
}
?> |
...