JSON全称为JavaScript Object Notation,是一种轻量级的文本数据交换格式,与语言无关。
JSON语法里数据用值/键对表示,而对象由多个数据组成:
{ "firstName":"John" , "lastName":"Doe" }
例如:
数组用[]表示:
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
javascript可以与JSON对象进行交互:
var employees = [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName": "Jones" }
];
employees[1].firstName="Jonatan";
document.getElementById("fname").innerHTML=employees[1].firstName;
阅读(1605) | 评论(0) | 转发(0) |