JSON
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式。它基于JavaScript(Standard ECMA-262 3rd Edition - December 1999)的一个子集。 JSON采用完全独立于语言的文本格式,但是也使用了类似于C语言家族的习惯(包括C, C++, C#, Java, JavaScript, Perl, Python等)。这些特性使JSON成为理想的数据交换语言。 易于人阅读和编写,同时也易于机器解析和生成(网络传输速度)。
JSON 语法
1
|
"firstName":"John" |
1
|
firstName="John" |
1
|
{"firstName":"Brett","lastName":"McLaughlin","email":"aaaa"}
表示数组
|
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
|
{"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
|
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 //Valueis"fantasy" people.musicians[3].lastName //Undefined.Thisreferstothefourthentry,andthereisn‘tone people.programmers[2].firstName //Valueis"Elliotte" |
1
|
people.musicians[1].lastName= "Rachmaninov" ; |
原文地址:http://blog.csdn.net/agonie201218/article/details/45461499