可能重复:
我有一个嵌套数据结构/JSON,如何访问特定值?
这是我的 ajax 调用的 js 代码
var UserArr = new Array();
$.ajax({
type: 'POST',
data: postJSONData,
url: 'PrivateSpace.asmx/GetUserDetails',
dataType: 'json',
async: false,
contentType: 'application/json; charset=utf-8',
success: function success(response) {
debugger;
UserArr = response.d;
},
error: function failure(response) {
alert('failed');
}
});
例如:UserArr 将是这样的:
[0] will have userid: 101, username: jack
[1] will have userid: 102, username: jones
我试过这样,但它似乎不起作用
for (var i = 0; i < UserArr.length; i++) {
User_ID = // i couldn get like UserArr.userid
Name = // i couldn get like UserArr.username
}
请帮帮我..