JSON understanding

Transferred from: http://blog.csdn.net/qyf_5445/article/details/8635578 (json is very comprehensive)

     http://www.cnblogs.com/haitao-fan/p/3908973.html (application understanding of json)

 

 

Judging from the structure of json, data can be divided into three types
. The first type is scalar (scalar), which is a single string (string) or numbers (numbers), such as the single word "Beijing". 
The second type is sequence (sequence), that is, several related data are juxtaposed together in a certain order, also known as array (array) or List (list), such as "Beijing, Tokyo". 
The third type is mapping, which is a name/value pair (Name/value), that is, the data has a name and a corresponding value, which is also called hash or dictionary (dictionary), such as "Capital: Beijing". 
JSON (JavaScript Object Notation) is a lightweight data exchange format, its rules are very simple and interesting: 
1) The parallel data are separated by commas (","). 
2) Mappings are represented by colons (":"). 
3) A collection (array) of parallel data is represented by square brackets ("[]"). 
4) Mapped collections (objects) are represented by curly brackets ("{}"). 
According to this rule, it can be understood as follows: 
1. Arrays are created with "[]", objects are created with "{}", and Json is basically an array or object created with [] or {}, otherwise an ordinary string It is meaningless; 
2. Whether it is an array or an object, the elements between them are separated by ","; 
3. Inside the object, the (attribute) name and value are separated by ":", and must use ":" "Separated, no attribute name or value can exist alone; 
4. Objects and arrays can be nested in each other, that is, an element in an array can be an object or an array, and the value of an attribute in an object can be a An object can also be an array.

1) 文本:"uname=alice&moblieIpt=110&birthday=1943-03-11"

2) json object: {uname:'vic',mobileIpt:'110',birtday:'2013-02-12'}

3) json array: the array is created with []. The objects in the array are created with {}.
Whether it is an array or an object--the elements between them are used,
and the property names and values ​​inside the object are separated by: spaced apart, not If the attribute name or value exists alone, it must be matched with

[
{"name":"uname","value":alcie"},
{"name":"mobileIpt","value":"110"},
{"name" :"birthday","value":2011-12-02}
]

 

解释规则4(对象和数组可以互相嵌套)
var china= {
beijing:{name:"北京",area:"16000",haidian:{name:"海淀区"}}, 
shanghai:{name:"上海",area:"10000",minhang:{name:"闵行区"}}
}; 
alert(china.beijing.haidian.name); 
alert(china.shanghai.minhang.name); //分别弹出“海淀区”和“闵行区”。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325565255&siteId=291194637