JSON format and serialize serialization-Lu Xiaolu
I. JSON formatting
1. what is JSON?
JSON is a data storage format used to communicate the interaction between client Javascript and server PHP. We can transmit the JSON string generated in PHP to the front-end Javascript, and compress cirpt can easily apply the JSON string.
2. how to use JSON
You can use json_encode () and json_decode () functions for JSON operations in PHP-one encoding and one decoding. Json_encode () can convert an array into json text data for easy storage and reading, while json_decode () can directly convert json data into an array for easy calling.
Result:
{"Name": "\ u5218 \ u7490", "nick": "\ u7490 \ u5c0f \ u7490", "age": "26", "contact ": {"phone": "13718136109", "address": "\ u5317 \ u4eac \ u5f97 \ u8c46 "}}
3. asynchronous interaction between JSON-format data and WEB front-end JS
After PHP converts an array into json data using json_encode (), this json string is equivalent to an object in JavaScript. after being assigned to a variable, you can operate on this array.
Profile. php
'Liu Lu', 'Nick '=> 'Lu Xiaolu', 'age' => '26', 'Contact '=> array ('phone' => '123 ', 'address' => 'Beijing ifdoo'); $ str = json_encode ($ arr); echo "getProfile ($ str)";?>