任何人都可以告诉我如何从下面的json中“item2”访问数据吗?
JSON
item1: [
{ "location": [
{"latitude": value, "longitude": value, "fileName": value }
],
"links": [
{"latitude": value, "longitude": value, "fileName": value },
{"latitude": value, "longitude": value, "fileName": value },
{"latitude": value, "longitude": value, "fileName": value }
]
}
],
item2: [ //repeat of above ]
答案 0 :(得分:1)
这将帮助您从json中迭代item2
<script language="javascript" >
document.writeln("<h2>JSON array object</h2>");
var books = { "Java" : [
{ "Name" : "Java is Simple", "price" : 500 },
{ "Name" : "The Complete Reference", "price" : 600 }
],
"Spring" : [
{ "Name" : "Spring is mvc", "price" : 300 },
{ "Name" : "Basics Spring", "price" : 200 }
]
}
var i = 0
document.writeln("<table border='2'><tr>");
for(i=0;i<books.Java.length;i++)
{
document.writeln("<td>");
document.writeln("<table border='1' width=100 >");
document.writeln("<tr><td><b>Name</b></td><td width=50>"
+ books.Java[i].Name+"</td></tr>");
document.writeln("<tr><td><b>Price</b></td><td width=50>"
+ books.Java[i].price +"</td></tr>");
document.writeln("</table>");
document.writeln("</td>");
}
for(i=0;i<books.Spring.length;i++)
{
document.writeln("<td>");
document.writeln("<table border='1' width=100 >");
document.writeln("<tr><td><b>Name</b></td><td width=50>"
+ books.Spring[i].Name+"</td></tr>");
document.writeln("<tr><td><b>Price</b></td><td width=50>"
+ books.Spring[i].price+"</td></tr>");
document.writeln("</table>");
document.writeln("</td>");
}
document.writeln("</tr></table>");
</script>