网站建设资讯

NEWS

网站建设资讯

json数据格式

JSON数据格式

成都创新互联公司于2013年成立,先为禹城等服务建站,禹城等地企业,进行企业商务咨询服务。为禹城企业网站制作PC+手机+微官网三网同步一站式服务解决您的所有建站问题。

ex01

/*

*类对象,封闭成员属性

*classPeople{

*Stringfirstname

*Stringlastname

*Stringemail

*}

*

*Peoplepeople=newPeople();

*

*people.firstname

*people.lastname

*people.email

*

*/

/*

*json格式表示一个对象,键值相对

*格式:{key01:value01,key02:value02}

*

*/

varpeople={"firstname":"zhang","lastname":"sanfeng","email":"keni@com"}

//alert("people"+people)

//alert("people")

////输出peopel的first属性的值,即zhang

alert("名:"+people.firstname);

//输出peopel的lastname属性的值,即sanfeng

alert("姓:"+people.lastname);

//输出peopel的email属性的值,即keni@com

alert("电子邮箱:"+people.email);

ex02

/*

*json格式表示一个对象

*格式:[

*{key01:value01,key02:value02},

*{key01:value01,key02:value02}

*]

*

*/

//json数组集合,存放两个对象,每个对象有三个属性

varpeople=[

{"firstname":"zhang1","lastname":"sanfeng1","email":"keni1@com"},

{"firstname":"zhang2","lastname":"sanfeng2","email":"keni2@com"}

]

alert("对象长度"+people.length);//长度为2

//输出对象数组中第二个对象的lastname属性

alert("第二个对象的lastname属性:"+people[1].lastname);//输出zhang2

ex03

/*

*json格式表示一个对象

*格式:{key:

*[

*{key01:value01,key02:value02},

*{key01:value01,key02:value02}

*]

*}

*

*/

varpeople={"program":

[

{"firstname":"zhang1","lastname":"sanfeng1","email":"keni1@com"},

{"firstname":"zhang2","lastname":"sanfeng2","email":"keni2@com"}

]

}

alert(people.program.length);//输出program的长度为2

alert(people.program[1].lastname);//输出people对象中program属性中第二个对象的lastname

ex04

/*

*json格式表示一个对象

*格式:{key1:

*[

*{key01:value01,key02:value02},

*{key01:value01,key02:value02}

*],

*key2:

*[

*{key01:value01,key02:value02},

*{key01:value01,key02:value02}

*]

*}

*

*/

varpeople={"program1":

[

{"firstname":"zhang11","lastname":"sanfeng11","email11":"keni1@com"},

{"firstname":"zhang12","lastname":"sanfeng12","email12":"keni2@com"}

],

"program2":

[

{"firstname":"zhang21","lastname":"sanfeng21","email":"keni21@com"},

{"firstname":"zhang22","lastname":"sanfeng22","email":"keni22@com"}

],

"program3":

[

{"firstname":"zhang31","lastname":"sanfeng31","email":"keni31@com"},

{"firstname":"zhang32","lastname":"sanfeng32","email":"keni32@com"}

]

}

//输出people对象program3对象中第一个对象的last的值

alert(people.program3[0].lastname);

ex05

varpeople={

"username":"zhang",

"sex":"male",

"tel":{"phone":"110","cell":"13812345678"},

"address":[

{"city":"tieling","postcode":"110"},

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

]

}

alert(people.username);

alert(people.tel.cell);

alert(people.address[1].city);

alert(people.address[1].postcode)


网站题目:json数据格式
文章链接:http://njwzjz.com/article/iigpgj.html