PHP and JavaScript are actually very handy to interact with, and PHP native also provides support for JSON format. The main include JSON encoding and decoding two functions:
1 Json_endoce:http://cn.php.net/json_encode
2 Json_dedoce:http://cn.php.net/json_decode
json_encode-encodes the variables and returns the JSON form of the value values, for example:
1 <!--? php
2 $arr = Array (' A ' =-->1, ' B ' =>2, ' C ' =>3, ' d ' =>4, ' e ' =>5);
3 echo Json_encode ($arr);
4?>
The above code executes after output:
1 {"A": 1, "B": 2, "C": 3, "D": 4, "E": 5}
If the data source to encode is (typically an array), the value contains Chinese, and the output is Unicode encoding after json_encode processing.
1 <!--? php
2 $arr = Array (' A ' =--> ' Web programming Technology Exchange Network ');
3 echo Json_encode ($arr);
4?>
The above code executes after output:
1 {"A": "\u8292\u679c\u5c0f\u7ad9"}
PHP Bottom has done Unicode processing, if it is not intuitive enough, you can use the UrlEncode and UrlDecode method to bypass the transcoding process of Unicode:
1 $arr = Array (' A ' =>urlencode (' Web Programming Communication network ');
2 echo UrlDecode (Json_encode ($arr));
The above code executes after output:
1 {"A": "Web Programming Technology Network"}
PHP output Chinese JSON string