温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

json数据格式

发布时间:2020-06-29 10:54:30 来源:网络 阅读:554 作者:yixiaoqun 栏目:web开发

JSON数据格式

ex01

<scriptlanguage="JavaScript">

/*

*类对象,封闭成员属性

*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")

////输出peopelfirst属性的值,zhang

alert(":"+people.firstname);

//输出peopellastname属性的值,sanfeng

alert(":"+people.lastname);

//输出peopelemail属性的值,keni@com

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

</script>

ex02

<scriptlanguage="JavaScript">

/*

*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

</script>

ex03

<scriptlanguage="JavaScript">

/*

*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

</script>

ex04

<scriptlanguage="JavaScript">

/*

*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);

</script>

ex05

<scriptlanguage="JavaScript">

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)

</script>

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI