JavaScript JSON语法
Posted 15037075275z
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript JSON语法相关的知识,希望对你有一定的参考价值。
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);
以上是关于JavaScript JSON语法的主要内容,如果未能解决你的问题,请参考以下文章