We all know that using the function Json_encode () can quickly and easily convert an array into JSON-encoded, but if the array value exists in Chinese, Json_encode converts the Chinese to Unicode encoding, for example:
<? PHP $array Array (' China ', ' America ', ' Gao Shuai ', ' Bai Fu Mei ', ' Dick Silk '); echo json_encode ($array);
The results are printed as follows:
["\u4e2d\u56fd", "\U7F8E\U56FD", "\u9ad8\u5bcc\u5e05", "\u767d\u5bcc\u7f8e", "\u5c4c\u4e1d"]
This format is also our most common, and can be parsed in JavaScript. But in some cases I do not need to convert Chinese to Unicode encoding, if it is handled. The solution is to first UrlEncode () the Chinese. Then turn to JSON. The JSON transformation can be resolved by UrlDecode () :
$data Array (); foreach ($arrayas$key=$value) { $dataUrlEncode ($value);} Echo UrlDecode (Json_encode ($data));
Printing results are:
["China","United States","high-rich handsome","White rich beauty","Dick Silk"]
In this way, our problem is solved, the common weather-forecasting interface return value is this. It is important to note that Json_encode () only supports UTF-8 encoding . So if it's another code, you need to convert it. such as: Iconv (), of course, a lot of methods, in the PHP5.4 version of Json_encode () has supported the non-conversion encoding, for example: Json_encode ($str, Json_unescaped_unicode)