I want to know how can I retrieve the values from the json if the json returns an array of result?
我想知道如果json返回结果数组,我如何从json中检索值?
Note: the first array is not the same length of the second array but the first array is will be always be less than the second array
注意:第一个数组与第二个数组的长度不同,但第一个数组总是小于第二个数组
Here's what I do as of now and get this error:
这是我现在所做的,并得到此错误:
Here's my jquery code:
这是我的jquery代码:
success: function(data){
var toAppend = '';
if(typeof data === "object"){
for(var i=0;i<data.length;i++){
toAppend += '<tr><td colspan="2">'+data[0][i]['m-asin'][0]+'</td></tr>';
toAppend += '<tr><td>'+data[1][i]['asin'][0]+'</td><td>'+data[1][i]['size'][0]+'</td></tr>';
}
$('.data-results').append(toAppend);
}
}
ANd I think no need for php code since it is working because it returns the expected results. Any help will be a big thing thanks!
我认为不需要PHP代码,因为它正在工作,因为它返回预期的结果。任何帮助都将是一件大事,谢谢!
1 个解决方案
#1
2
data[0][i]
gives you the i-th property of the first data element. You'll need to revert it: data[i][0]
.
data [0] [i]为您提供第一个数据元素的第i个属性。你需要还原它:data [i] [0]。
Or otherwise, you'll need to alter the loop, to get the number of elements in data[0]:
或者,您需要更改循环,以获取data [0]中的元素数量:
for(var i=0; i<data[0].length; i++){
#1
2
data[0][i]
gives you the i-th property of the first data element. You'll need to revert it: data[i][0]
.
data [0] [i]为您提供第一个数据元素的第i个属性。你需要还原它:data [i] [0]。
Or otherwise, you'll need to alter the loop, to get the number of elements in data[0]:
或者,您需要更改循环,以获取data [0]中的元素数量:
for(var i=0; i<data[0].length; i++){