Json--json Learn how to get started (Learn what JSON is)

Source: Internet
Author: User
Tags php server

JSON formatting tool: Tool.oschina.net/codeformat/json


JSON definition

JSON (JavaScript Object Notation) is a lightweight data interchange format with good readability and easy-to-write features. Data exchange between different platforms is possible. JSON uses a very high compatibility, completely independent of the language text format, but also has a similar to the C language habits (including C, C + +, C #, Java, JavaScript, Perl, Python, etc.) the behavior of the system. These features make JSON an ideal data exchange language.

JSON based on JavaScript programming Language, Standard ECMA-262 a subset of 3rd Edition-december 1999


format of JSON

content excerpted from:http://www.ruanyifeng.com/blog/2009/05/data_types_and_json.html

At the beginning of 21st century, Douglas Crockford looked for a simple data interchange format that could exchange data between servers. The universal data Exchange language was XML at the time, but Douglas Crockford thought that XML generation and parsing were too cumbersome, so he proposed a simplified format, json.

JSON specifications are very simple, with only one page hundreds of words can be said clearly, and Douglas Crockford claims that this specification never need to upgrade, because the provisions of the provision.

1) The data is separated by commas (",").

2) The map is represented by a colon (":").

3) a set (array) of side data is expressed in square brackets ("[]").

4) The Set of Mappings (objects) are represented by curly braces ("{}").

The above four rules are all content in JSON format.

For example, the following sentence:

"Beijing's area is 16800 square kilometers, the resident population is 16 million people." The area of Shanghai is 6400 square kilometers, the resident population is 18 million. "

Written in JSON format:

[

{"City": "Beijing", "area": 16800, "Population": 1600},

{"City": "Shanghai", "area": 6400, "Population": 1800}

]

If you know the structure of the data beforehand, the above wording can be further simplified:

[

["Beijing", 16800,1600],

["Shanghai", 6400,1800]

]

As you can see, JSON is easy to learn and use. So, in just a few years, it replaced XML as the most popular data interchange format on the Internet.

I suspect that Douglas Crockford must have known beforehand that the data structure can be simplified into three forms, otherwise how can the JSON be defined so refined!


the pros and cons of JSON-yoy XML

The advantages of JSON:
A. Data format is relatively simple, easy to read and write, the format is compressed, occupy small bandwidth;
B. Easy to parse, client-side JavaScript can simply pass the eval () to the JSON data read;
C. Support multiple languages, including ActionScript, C, C #, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby and other server-side language, convenient for server-side analysis;
D. In the world of PHP, there are already Php-json and json-php appear, partial to the PHP serialization of the program directly call, PHP server-side objects, arrays, etc. can be directly generated JSON format, convenient for client access extraction;
E. Because the JSON format can be used directly for server-side code, greatly simplifies the server-side and client code development, and the completion of the task is not changed, and easy to maintain.
The drawbacks of JSON
A. There is no XML format so popular and happy to use widely, without XML so universal;
The B.json format is now in the initial stage of promotion in Web service.

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.