PHP and JavaScript are actually handy, and PHP native also provides support for the JSON format. Mainly includes JSON encoding and decoding two functions:
Json_endoce:http://cn.php.net/json_encode
json_dedoce:http://cn.php.net/json_decodejson_encode-the variable in JSON and returns the JSON form of the value, for example:
$arr = Array (' A ' =>1, ' B ' =>2, ' C ' =>3, ' d ' =>4, ' e ' =>5);
echo Json_encode ($arr);
?>
The above code executes after the output:
{"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
If you want to encode a data source (typically an array), the value contains Chinese, and the output is Unicode encoding after json_encode processing.
$arr = Array (' A ' => ' Mango Station ');
echo Json_encode ($arr);
?>
The above code executes after the output:
{"A": "U8292u679cu5c0fu7ad9"}
The PHP bottom has done Unicode processing, if it is not intuitive enough, you can use the UrlEncode and UrlDecode methods to bypass the transcoding for Unicode process:
$arr = Array (' A ' =>urlencode (' Mango Station '));
Echo UrlDecode (Json_encode ($arr)); Output after execution of the above code:
{"A": "Mango Station"}