JSON format and serialize serialization-Lu Xiaolu

Source: Internet
Author: User
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)";?>
  • Html page calls php file

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.