JSON学习
是什么?
- JSON是javascript object notation的缩写,能够方便的描述javascript对象,用于传输。
- 是纯文本的轻量级数据交换格式,代替xml应用于传输的解析不方便性
形式?
- {name:value} 组成。如:var user = {"name":{"firstname":"coral", "lastname":"shanshan"}, "gender":"female"};
- value可以是字符串,布尔值,对象,有序列表
- 有序列表(数组):[]表示,逗号分隔
用途?
- json可以方便的表示javascript对象:
如var user = {"name":{"firstname":"coral", "lastname":"shanshan"}, "gender":"female"};
- javascript也可以方便的表示为json对象
String jsonText = user.toJSONString()
用于什么情况下的数据传输?
----------------------------------------------
附上网上copy的json实例:
{ "firstName": "John",
"lastName": "Smith",
"male": true,
"age": 25,
"address":
{
"streetAddress": "21 2nd Street",
"city": "New York",
"state": "NY",
"postalCode": "10021"
},
"phoneNumber":
[
{
"type": "home",
"number": "212 555-1234"
},
{
"type": "fax",
"number": "646 555-4567"
}
]
}