我正在使用 JavaScript JSON 对象。我不确定这是编写 JSON 对象的正确方法:-
var address={
details:{
"martin":[{"full_name":"James Martin"},{"address":"Florida"},{"phone":"897657834"}],
"luthar":[{"full_name":"Luther king"},{"address":"Boston"},{"phone":"9856568789"}],
"jonson":[{"full_name":"Jonson vierra"},{"address":"New york"},{"phone":"98654567887"}]
}
}
现在,我想在表格中显示每个人的每个元素。我可以通过编写手动执行此操作:
<table border=1>
<tr>
<td><script>document.write(address.details.martin[0].full_name)</script></td>
<td><script>document.write(address.details.martin[1].address)</script></td>
<td><script>document.write(address.details.martin[2].phone)</script></td>
</tr>
</table>
对所有 3 个人都这样,但我想通过使用循环来获取每个人的全部细节。我怎样才能通过使用循环轻松做到这一点?