1 <? PHP 2 Header ("CONTENT-TYPE:TEXT/HTML;CHARSET=UTF-8;" ); 3 $arr Array (' Version_code ' =>2, ' version_name ' = ' updateversion ', ' versoin_desc ' + ' Update the map function ', ' versoin_path ' + ' http ://nnddkj.com/busiot/apk/busiot.apk '); 4 echo json_encode ($arr); 5 ? >
As the code above, the string variable is converted to JSON format output, but the output is as follows:
{"Version_code": 2, "Version_name": "Updateversion", "Versoin_desc": "\U66F4\U65B0\U4E86\U5730\U56FE\U529F\U80FD", " Versoin_path ":" http:\/\/nnddkj.com\/busiot\/apk\/busiot.apk "}
That is, all the Chinese in the array are missing after the Json_encode or appear \u2353.
The workaround is to use the UrlEncode () function to handle the following, before Json_encode, all the contents of the array are processed with UrlEncode (), and then converted to a JSON string with Json_encode (). Finally, I use UrlDecode () to turn the encoded Chinese back.
1 <? php 2 header ("content-type:text/html; Charset=utf-8; " 3 $arr = (' Version_code ' =>2, ' version_name ' = ' updateversion ', ' versoin_desc ' = urlencode (' Updated map function '), ' Versoin_path ' =>urlencode (' http://nnddkj.com/BusIot/APK/ busiot.apk ' 4 UrlDecode (Json_encode ( $arr 5 ?
Output: {"Version_code": 2, "Version_name": "Updateversion", "Versoin_desc": "Updated map function", "Versoin_path": "/HTTP// nnddkj.com/busiot/apk/busiot.apk "}
Get..
Attached: Json_decode encodes a JSON-formatted string, while Json_encode JSON-encodes the variable
Json_decode - encode a string in JSON format
Description
Mixed Json_decode (String $json [, bool $assoc])
Accepts a JSON-formatted string and converts it to a PHP variable, $ASSOC, when this argument is TRUE, returns an array instead of an object
Json_encode: detailed asked Niang
Convert string variables into JSON format in PHP