我从JSON数组获取数据时遇到问题。
这是JSON代码:
[
[
4.440216064453125,
[1,0,0,0,1,1,1,0,0,1,1],
0,
"Test0",
"Test0",
[129]
],
[
4.452216148376465,
[1,0,0,0,1,1,1,1,1,0,0],
1,
"Test1",
"Test1",
[1,0,0]
]
]
我想提醒“ 1”值。它是“ Test1”。
这是JS代码:
function inspect(){
$.ajax({
type: "GET",
url: 'addtest.json',
dataType: "JSON",
async : false,
success: function(JSON) {
alert(JSON.array[1])
},
error: function(JSON) {
alert("Error")
}
});
}
它无法正常工作。
能否请你帮忙 ?
最佳答案
JSON
是JavaScript中定义的对象,请使用另一个变量
function inspect(){
$.ajax({
type: "GET",
url: 'addtest.json',
dataType: "JSON",
async : false,
success: function(response) {
alert(response[1][3]); // For showing "Test1"
},
error: function(err) {
alert(err)
}
});
}
关于javascript - 如何访问数组中的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22300908/