JSON summary and its parsing (for Java). __php

Source: Internet
Author: User
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

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.