first, JSON introduction
JSON (JavaScript Object notation), similar to XML, is a data interchange format, such as Java, which produces a data that wants to be given to JavaScript, and uses JSON in addition to XML;
The advantage of JSON over XML is that it is simple to express;
Official website: http://www.json.org/
JSON is an X in Ajax (that is, it can replace XML); ------from the founder of JSON;
Note: JSON is not a document format, there are no *.json documents, general JSON-formatted documents exist in TXT, and XML can be a standard;
Two, JSON data structure
JSON has two types of data structures:
(1) Map, also known as object; }
(2) array;[...]
That is to say, all JSON objects are represented in these forms;
1.Map
Simply put is the map in Java, name-value pairs of the form given, the name and value between ":" Separated by "," between two map separated by "," the general representation is as follows:
{' Key1 ': ' value1 ', ' key2 ': ' value2 '}
The following is the official website chart:
2.Array
is an array of ordinary meanings, the general form is as follows:
[' arr1 ', ' arr2 ', ' arr3 '];
The following is the official website chart:
The value in the figure can be:
Summary:
(1) There are only two types of JSON data structures;
(2) can be nested representations, such as array can be nested object, etc.;
(3) Remember: object is expressed as {}, array is represented by [];
three, JSON and XML interchange examples
Any XML mentioned above can be converted into a JSON package;
1. Simple XML
XML format:
[HTML] view plain copy <person> <name>xiazdong</name> <age>20</age> </person>
JSON format:
[HTML] view plain copy {' name ': ' Xiazdong ', ' Age ': 20}
2. Complex XML
XML format:
[HTML] View plain copy <section> <title> book</title> <signing> <author name= "Author-1"/> <book title= "Book1" price= "$11"/> </signing