First, the syntax structure of JSON
1. Basic structure
1> a collection of name/value pairs (objects, records, structures, dictionaries, hash tables ...)
A name/value pair is an element, the element name and value are separated by the " : " number, and multiple name/value pairs are combined into a JSON structure, and the name/value pairs are separated by " , ".
Example: JSON structure:
{ "name": "AJAX", "sex": "Man"}
2> sequence Table (array) of values
Example:
["AJAX", "HTML", "PHP"]
2. Brace save object, square brackets Save array
3. Objects can hold multiple name/value pairs, and arrays can hold multiple objects
Example:
{" student": [ {"Name": "Charles", "id": "123"}, {"Lesson": "Math", "Teacher": "Tom"}, {"Address": " AAA "," Number ":" 1 "}]}
Ii. types of values in JSON
1. Object 2. Array 3. Number 4. String 5. Boolean value 6.null
Third, the language support of JSON
There are many languages that support JSON: Javascript, PHP, C #, C, C + +, Java ...
1.JSON is based on JavaScript, so the basic structure of JavaScript native support for Json,json is actually the object and data in JavaScript,
With the function--eval (string) in JavaScript, you can convert the JSON data to a JavaScript object.
Example:
var obj =eval ("(" + Json_txt + ")");
Note: The text must be wrapped in parentheses to avoid errors.
The 2.PHP uses Json,json to support JSON from version 5.2, implemented by Json_encode () and Jsno_decode () two methods.
Example:
Suppose $book is an example of an array, a number, and so on, converting $book to JSON format:
$json
Json_decode () Converts the JSON to a PHP object.
Iv. advantages and disadvantages of JSON
1. Advantages:
1>json is simpler than XML
2> Easy to parse
3> Simple Structure
2. Disadvantages:
There is no namespace mechanism like XML
Ajax Learning--The ideal data exchange language JSON