标签:++ 键值对存储 json for 存储 bsp i++ var 调用
1.创建JSON
JSON数距的是以键值对存储。
语法:
var JSOM名 ={"name":"张三","sex":"女","age":19};
var JSOM名 ={"student":[{"name":"张三","sex":"男","age":18},{"name":"李四","sex":"女","age":19},{"name":"王五","sex":"女","age":19}]};
var JSOM名 ={"student":{"name":"张三","sex":"男","age":18}};
2.调用JSON
(1)
var JSOM名 ={"name":"张三","sex":"女","age":19};
调用:alert(JSOM名.name);
(2)
var JSOM名 ={"student":[{"name":"张三","sex":"男","age":18},{"name":"李四","sex":"女","age":19},{"name":"王五","sex":"女","age":19}]};
调用:
var arr = JSOM名.student;
for(i=0;i<arr.length;i++)
{
alert(arr[i].age+arr[i].name+arr[i].sex)
}
(3)
var JSOM名 ={"student":{"name":"张三","sex":"男","age":18}};
调用:
alert(JSOM名.student.name);
标签:++ 键值对存储 json for 存储 bsp i++ var 调用
原文地址:http://www.cnblogs.com/zhang1999/p/7144799.html