JSON Code Writing specification

Source: Internet
Author: User

  In the Ajax implementation before and after the data interaction, usually using the JSON data format, for JSON, there are strict code specifications, once the format problems, can not display the corresponding effect, but also not in the console error. So what are the specifications for JSON writing?

What is JSON?

  In front of the background of the interaction, it is usually necessary to pass the message to each other, it requires a two-way "understand the language", the data format here represents the language. JSON is a "language" that can be understood back and forth.

Types of JSON

 JSON also has different forms of organization, one is a JSON object, and the other is a JSON array. Therefore, in the written code, you need to follow the basic object, the way the array is written.

1. Array mode

1         [{  2             "City": "Beijing",  3             "num": 5 4        }, { 5             " City ":" ShenZhen ",  6             " num ": 5 7        }, {  8             " City ": "Xiamen",  9             "num": 5         }]

2. Object mode

1         {2"User": "Zhangsan",3 4"Type": "Work",5 6"Team" : [{7"City": "Beijing",8"Num": 39             }, {Ten"City": "GuangZhou", One"Num": 3 A             }, { -"City": "Shanghai", -"Num": 3 the             }] -}
Considerations for writing JSON

1. Strings in arrays or objects must use double quotation marks and cannot use single quotes

{' user ': ' Zhangsan '}//illegal
{"User": ' Zhangsan '}//illegal

2. The member name of the object must use double quotation marks

{"User": "Zhangsan"}//Legal

3. After the last member of an array or object, you cannot add commas

1         [{2             "City": "Beijing",3             "num": 5,//Illegal 4         }, {5             "City": "ShenZhen",6             "num": 5,//illegal 7         }]

4. The value of each member of an array or object, either a simple value or a composite value. Simple values are divided into four types: strings, numeric values (which must be represented in decimal), Booleans, and nulls (NaN, Infinity,-infinity, and undefined are all converted to null). There are two types of composite values: objects in JSON format and arrays that conform to JSON format.

{"Age": ox16}//illegal, value must be decimal
{"City": undefined}//use undefined, illegal
1 NULL , 2 function () {3   console.log ("Error usage"); 4 }}//json cannot use custom functions or system built-in functions (such as date ())

JSON Code Writing specification

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.