JSON, json online parsing _ PHP Tutorial

Source: Internet
Author: User
JSON and json are parsed online. JSON: json (JavaScriptObjectNotation) is a lightweight data exchange format. It is based on a subjson of JavaScript (StandardECMA-2623rdEdition-December1999), JSON online parsing

Brief description:

JSON (JavaScript Object Notation) is a lightweight data exchange format. It is based on a subset of JavaScript (Standard ECMA-262 3rd Edition-December 1999.

JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C, C ++, C #, Java, JavaScript, Perl, Python, and so on ).

These features make JSON an ideal data exchange language. Easy for reading and writing, and easy for machine parsing and generation.

JSON syntax:

JSON syntax is a subset of JavaScript syntax.

JSON syntax rules

Data in name/value pairs

Data is separated by commas (,).

Brackets save objects

Square brackets save the array

JSON name/value pair

JSON data is written in the format of name/value pair.

Name/value pair includes the field name (in double quotation marks), followed by a colon, followed by a value:

1

"FirstName": "John"

This is easy to understand. it is equivalent to this JavaScript statement:

1

FirstName = "John"

JSON value:

Number (integer or floating point number)

String (in double quotation marks)

Logical value (true or false)

Array (in square brackets)

Object (in curly brackets)

Null

Comparison with XML:

1. readability

The readability of JSON and XML is comparable. one side is a simple syntax and the other is a standard tag form, making it difficult to distinguish between the two.

2. scalability

XML is inherently highly scalable, and JSON is also available. nothing is XML that can be extended, but JSON cannot be extended. However, JSON can store Javascript composite objects at the home site of Javascript, which has an incomparable advantage of xml.

3. encoding difficulty

XML has rich coding tools, such as Dom4j and JDom, and JSON also provides tools. Without tools, I believe that skilled developers can quickly write the desired xml document and JSON string. However, the xml document requires many more structural characters.

4. Difficulty in decoding

XML can be parsed in two ways:

One is to parse the document model, that is, index a group of tags through the parent tag.

For example, xmlData. getElementsByTagName ("tagName"), but this method is used when the document structure is known in advance and cannot be encapsulated.

Another method is to traverse nodes (document and childNodes ). This can be achieved through recursion, but the parsed data is still in different forms and often cannot meet the pre-requirements.

It is difficult to parse such extensible structure data.

The same is true for JSON. If you know the JSON structure in advance, it is amazing to use JSON for data transmission. you can write code that is very practical, beautiful, and readable. If you are a pure front-end developer, you will love JSON very much. However, if you are an application developer, you are not that fond of it. after all, xml is the real structured markup language for data transmission.

However, parsing JSON without knowing the JSON structure would be a nightmare. Code will become redundant, and the results will be unsatisfactory. However, this does not affect the choice of JSON by many front-end developers. Because toJSONString () in json. js can see the JSON string structure. Of course, this string is not used. this is still a nightmare. After a common JSON user sees this string, the JSON structure is very clear, making it easier to operate JSON.

The preceding section only parses the xml and JSON data transmitted in Javascript. In the Javascript field, JSON is a battle at home after all, and its advantage is of course far superior to xml. If Javascript composite objects are stored in JSON and do not know their structure, I believe many programmers are crying to parse JSON.

In addition to the above, there is another big difference between JSON and XML in terms of effective data rate. JSON is more efficient when transmitted as a data packet format, because JSON does not need to have a strict closed tag as XML does, which greatly improves the effective data volume compared with the total data packets, this reduces the transmission pressure on the network when the data traffic is equal.

Brief description: JSON (JavaScriptObjectNotation) is a lightweight data exchange format. It is based on a child of JavaScript (StandardECMA-2623rdEdition-December1999...

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.