html的json语法:json以中括号为最终括号,中括号里面放数组对象,对象用花括号括起来,其中数组对象内含多个属性,属性之间以逗号区分
基本模型:var json = [{ },{ },....]
1.只有一个对象的json:
<body>
<script>
var json = {"name":"Amy","age":"20"}
alert(json.name)
</script>
</body>
2.含有多个对象的json
<body>
<script>
var json1 = [{"name":"Amy","age":"20"},{"name":"Sky","age":"20"}]
alert(json1[1].name); //json1[0]就是json1里面的第一个对象
</script>
</body>
3.将数组对象封装到json
<body>
<script>
var arr = ["11","22","33","44","55","66","77","88"]
var json = []
for(var i=0;i<arr.length;i++){
json[i] = {"age":arr[i]}
}
alert(json[0].age) //11
alert(json[1].age) //22
</script>
</body>