标签:
1、对象:对象在js中表示为“{}”括起来的内容,数据结构为 {key:value,key:value,...}的键值对的结构,在面向对象的语言中,key为对象的属性,value为对应的属性值,所以很容易理解,取值方法为 对象.key 获取属性值,这个属性值的类型可以是 数字、字符串、数组、对象几种:
名称\值对
按照最简单的形式,可以用下面这样的 JSON 表示"名称 / 值对":
1
|
{"firstName":"Brett"} |
1
|
firstName=Brett |
1
|
{"firstName":"Brett","lastName":"McLaughlin","email":"aaaa"} |
2、数组:数组在js中是中括号“[]”括起来的内容,数据结构为
["java","javascript","vb",...],取值方式和所有语言中一样,使用索引获取,字段值的类型可以是 数字、字符串、数组、对象几种:
1
2
3
4
5
6
7
|
{ "people":[ {"firstName":"Brett","lastName":"McLaughlin","email":"aaaa"}, {"firstName":"Jason","lastName":"Hunter","email":"bbbb"}, {"firstName":"Elliotte","lastName":"Harold","email":"cccc"} ] } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
{ "programmers": [{ "firstName": "Brett", "lastName": "McLaughlin", "email": "aaaa" }, { "firstName": "Jason", "lastName": "Hunter", "email": "bbbb" }, { "firstName": "Elliotte", "lastName": "Harold", "email": "cccc" }], "authors": [{ "firstName": "Isaac", "lastName": "Asimov", "genre": "sciencefiction" }, { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" }, { "firstName": "Frank", "lastName": "Peretti", "genre": "christianfiction" }], "musicians": [{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" }, { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }] } |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
var people = { "programmers": [{ "firstName": "Brett", "lastName": "McLaughlin", "email": "aaaa" }, { "firstName": "Jason", "lastName": "Hunter", "email": "bbbb" }, { "firstName": "Elliotte", "lastName": "Harold", "email": "cccc" }], "authors": [{ "firstName": "Isaac", "lastName": "Asimov", "genre": "sciencefiction" }, { "firstName": "Tad", "lastName": "Williams", "genre": "fantasy" }, { "firstName": "Frank", "lastName": "Peretti", "genre": "christianfiction" }], "musicians": [{ "firstName": "Eric", "lastName": "Clapton", "instrument": "guitar" }, { "firstName": "Sergei", "lastName": "Rachmaninoff", "instrument": "piano" }] }; |
1
|
people.programmers[0].lastName; |
1
2
3
|
people.authors[1].genre // Value is "fantasy" people.musicians[3].lastName // Undefined. This refers to the fourth entry, and there isn‘t one people.programmers[2].firstName // Value is "Elliotte" |
1
|
people.musicians[1].lastName= "Rachmaninov" ; |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
{ id: ‘100000‘ , text: ‘廊坊银行总行‘ , children: [ { id: ‘110000‘ , text: ‘廊坊分行‘ , children: [ { id: ‘113000‘ , text: ‘廊坊银行开发区支行‘ , leaf: true }, { id: ‘112000‘ , text: ‘廊坊银行解放道支行‘ , children: [ { id: ‘112200‘ , text: ‘廊坊银行三大街支行‘ , leaf: true }, { id: ‘112100‘ , text: ‘廊坊银行广阳道支行‘ , leaf: true } ] }, { id: ‘111000‘ , text: ‘廊坊银行金光道支行‘ , leaf: true } ] } ] } |
1
2
3
4
|
{ "姓名":"大憨", "年龄":24 } |
1
2
3
4
5
6
|
{ "学生": [ {"姓名":"小明","年龄":23}, {"姓名":"大憨","年龄":24} ] } |
标签:
原文地址:http://blog.csdn.net/eflyings/article/details/51201892