Json,json Online parsing _php tutorial

Source: Internet
Author: User

Json,json Online Analysis


Briefly:

JSON (JavaScript Object Notation) is a lightweight data interchange format. It is based on a subset of JavaScript (standard ECMA-262 3rd edition-december 1999).

JSON takes a completely language-independent text format, but also uses a similar idiom to the C language family (c, C + +, C #, Java, JavaScript, Perl, Python, etc.).

These features make JSON an ideal data exchange language. Easy to read and write, but also easy to machine parse and generate.

JSON Syntax:

JSON syntax is a subset of JavaScript syntax.

JSON Syntax rules

Data in name/value pairs

Data is separated by commas

Curly braces Save Object

Square brackets Save Array

JSON Name/value pairs

The writing format for JSON data is: name/value pairs.

Name/value pairs include the field name (in double quotation marks), followed by a colon, and then the value:

1

"FirstName": "John"

This is easy to understand and is equivalent to this JAVASCRIPT statement:

1

Firstname= "John"

JSON Value:

Number (integer or floating point)

String (in double quotes)

Logical value (TRUE or FALSE)

Array (in square brackets)

Object (in curly braces)

Null

and XML comparison:

1. Readability

JSON and XML are comparable in readability, with simple syntax on one side and a canonical label on the other, which makes it difficult to distinguish between the winners and losers.

2. Scalability

XML is inherently well-extensible, and JSON certainly does, and nothing is XML that can be extended and JSON is not extensible. However, JSON in the JavaScript home combat, can store JavaScript compound object, with XML incomparable advantage.

3, coding difficulty

XML has a wealth of coding tools, such as dom4j, Jdom, and so on, and JSON also provides tools. Without tools, it is believed that skilled developers can quickly write the desired XML document and JSON string, but the XML document has many more characters on the structure.

4. Decoding difficulty

There are two ways to parse XML:

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

For example: Xmldata.getelementsbytagname ("TagName"), but this is to be used in the case of pre-knowledge of the document structure, unable to do a generic encapsulation.

Another way is to traverse nodes (document and ChildNodes). This can be achieved through recursion, but the parsed data is still different form, often can not meet the pre-requirements.

It must be difficult to parse any such extensible structure data.

The same is true for JSON. If you know the JSON structure in advance, it is wonderful to use JSON for data passing, and you can write very useful, aesthetically readable code. If you are a purely front-desk developer, you will love json very much. But if you're an app developer, it's not like that, after all, XML is the real structured markup language for data transfer.

It's a nightmare to parse JSON without knowing the structure of the JSON. Time and effort not to say, the code will become redundant procrastination, the results are also unsatisfactory. However, this does not affect many foreground developers to choose JSON. Because toJSONString () in json.js, you can see the string structure of the JSON. Of course not using this string, it's still a nightmare. When people who use JSON see the string, the JSON structure is straightforward and the JSON is easier to manipulate.

The above is the parsing of XML and JSON only for data passing in JavaScript. In JavaScript, JSON is a home battle, and its advantages are certainly far superior to XML. If you store JavaScript composite objects in JSON and don't know their structure, I'm sure a lot of programmers are crying and parsing json as well.

In addition to the above, there is another big difference between JSON and XML is the effective data rate. JSON is more efficient when it is transmitted as a packet format, because JSON does not need to have strict closing tags like XML, which allows the amount of effective data to be significantly higher than the total packet ratio, thus reducing the transmission pressure of the network in the case of equivalent data traffic.

http://www.bkjia.com/PHPjc/989818.html www.bkjia.com true http://www.bkjia.com/PHPjc/989818.html techarticle Json,json Online Analysis Brief: JSON (javascriptobjectnotation) is a lightweight data interchange 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.