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