JSON (note)

Source: Internet
Author: User

JSON (JavaScript Object Notation), is a lightweight data interchange format.

Four basic rules of syntax:

1. The parallel data is separated by commas (",").

2. The map is represented by a colon (":").

3. The data set (array) in parallel is denoted by square brackets ("[]").

4. The mapped collection (object) is represented by braces ("{}").

Cases:

"Beijing's area is 16800 square kilometers, the resident population is 16 million people." The area of Shanghai is 6400 square kilometers, the resident population is 18 million. ”

After converting to JSON format:

[

{"City": "Beijing", "area": "16800", "Population": "1600"},

{"City": "Shanghai", "area": "6400", "Population": "1800"}

]

Advantages: The data format is simple, easy to read and write, the format is compressed, occupy small bandwidth. Multi-lingual support.

Disadvantage: Required character encoding must be Unicode and can be used under any character set. be highly constrained. The grammar is too rigorous.

Important functions of PHP operation JSON:

Encryption: Json_encode ()

Decryption: Json_decode ()

Json_encode ()

One-dimensional arrays, multidimensional arrays to JSON conversions

Object into the JSON data format, converting only the public property values.

Json_decode ()

Convert JSON to object type and array type:

The JSON is converted to an array, requiring the second argument to be true. $jsonArray = Json_decode ($jsonStr, True).

The default conversion is object type. $json = Json_decode ($JSONSTR).

JSON (note)

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.