天天看點

json

JSON的規則: 對象是一個無序的“‘名稱/值’對”集合。一個對象以“{”(左括号)開始,“}”(右括号)結束。每個“名稱”後跟一個“:”(冒号);“‘名稱/值’ 對”之間使用“,”(逗号)分隔。

值(value)可以是雙引号括起來的字元串(string)、數值(number)、<code>true</code>、<code>false</code>、 <code>null</code>、對象(object)或者數組(array)。這些結構可以嵌套。

數組是值(value)的有序集合。一個數組以“[”(左中括号)開始,“]”(右中括号)結束。值之間使用“,”(逗号)分隔。

如:

var user =

{

"username":"andy",

"age":20,

"info": { "tel": "123456", "cellphone": "98765"},

"address":

[

{"city":"beijing","postcode":"222333"},

{"city":"newyork","postcode":"555666"}

]

}

alert(user.username);

alert(user.age);

alert(user.info.cellphone);

alert(user.address[0].city);

alert(user.address[0].postcode);

user.username = "Tom";

本文轉自linzheng 51CTO部落格,原文連結:http://blog.51cto.com/linzheng/1080906