js 操作 json

functionshowJSON(){
varuser=
{
"username":"andy",
"age":20,
"info":{"tel":"123456","cellphone":"98765"},
"address":
[
{"city":"beijing","postcode":"222333"},
{"city":"newyork","postcode":"555666"}
]
}
alert(user.username);
alert(user.age);
alert(user.info.cellphone);
alert(user.address[0].city);
alert(user.address[0].postcode);
}
如何在页面显示alert(user.username);
alert(user.age);
alert(user.info.cellphone);
alert(user.address[0].city);
alert(user.address[0].postcode);这些要显示的属性在body里面要怎么写?
HUX布斯
浏览 297回答 2
2回答

有只小跳蛙

如果只是要简单地写在页面上,用document.write。如果要放在一个div里面,例如那么document.getElementById('content').innerHTML='xxx';
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript