Understanding JSON
JSON(JavaScript Object Notation)是一种轻量级的数据交换语法,易于人类理解、易于机器解析。正如其名,JSON基于JavaScript脚本语言;然而,JSON本身是完全语言无关的。
JSON是RESTful web services之间进行数据传输的一种常用表示法。大多数编程语言提供了解析JSON数据的库,很多web框架现在也支持JSON格式的响应数据。由于JSON比XML占用存储空间小,它非常适合网速较低的情况。例如,移动设备通常连接速度较低。
JSON官方的internet media type是application/json,JSON文件一般用.json作为后缀名。
JSON格式由两部分定义。
值可以是一下任意一种类型,且可以嵌套:
这个对象包含三个域,name是一个string,age是一个number,member是一个boolean。
{
"name": "John",
"age": 35
"member": false
}
{
"indexes": [5, 10, 15, 20],
"names": ["John", "Elizabeth", "Mary"]
}
{
"firstName": "John",
"lastName": "Smith",
"birthday": "1975-01-31",
"spouse": {
"firstName": "Mary",
"lastName": "Smith"
},
"addresses": [
{
"description": "home",
"street": "123 Peachtree Ln",
"city": "Atlanta",
"state": "GA",
"postalCode": 30305
},
{
"description": "work",
"street": "456 Peachtree St",
"city": "Atlanta",
"state": "GA",
"postalCode": 30305
}
],
"phoneNumbers": [
{
"description": "home",
"number": "404-555-1234"
},
{
"description": "mobile",
"number": "678-555-1234"
}
]
}
原文:http://blog.csdn.net/kingzone_2008/article/details/18863527