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)