PHP and JavaScript are actually very convenient. PHP native also provides support for JSON format. Mainly includes two functions: JSON encoding and decoding:
Json_endoce: http://cn.php.net/json_encode
Json_dedoce: http://cn.php.net/json_decodejson_encode-encode the variable in JSON format and return the value, for example:
$ Arr = array ('A' => 1, 'B' => 2, 'c' => 3, 'D' => 4, 'E' => 5 );
Echo json_encode ($ arr );
?>
Output the code after execution:
{"A": 1, "B": 2, "c": 3, "d": 4, "e": 5}
For example, if the data source to be encoded (usually an array) contains Chinese characters, after json_encode processing, unicode encoding is output.
$ Arr = array ('A' => 'mango xiaozhan ');
Echo json_encode ($ arr );
?>
Output the code after execution:
{"A": "\ u8292 \ u679C \ u5C0F \ u7AD9 "}
Unicode processing has been performed at the underlying layer of PHP. If it is not intuitive enough, you can use the urlencode and urldecode methods to bypass the process of transcoding to unicode:
$ Arr = array ('A' => urlencode ('mango xiaozhan '));
Echo urldecode (json_encode ($ arr); output after the above code is executed:
{"A": "Mango xiaozhan "}