我希望从以下JSON数据中检索people_id
,username
,name
和people_type
。最后,我必须在bootstrap模式表中填充这些细节。下列
是我用来检索细节的jQuery代码:
.done(function (data_, textStatus_, jqXHR_) {
$.each(data_.people_list, function(key, value) {
$.each(value.details_list, function(k,v) {
console.log("Inside Loop:"+v.name);
$.each(v.role, function(k1,v1) {
console.log("Inside Another Loop for Role Name:"+v1.people_type);
});
});
});
})
目前我只尝试访问name
和people_type
。这是我在控制台上获得的输出:
Inside Loop:First Hand Details
Inside Another Loop for Role Name:undefined
Inside Loop:First Hand Details
Inside Another Loop for Role Name:undefined
Inside Loop:UAB Multiple Myeloma Registry
Inside Another Loop for Role Name:undefined
Inside Loop:First Hand Details
Inside Another Loop for Role Name:undefined
Inside Loop:First Hand Details
Inside Another Loop for Role Name:undefined
Inside Loop:First Hand Details
Inside Another Loop for Role Name:undefined
为什么people_type
未定义?我在网上看到当某个特定的东西不存在时,会得到undefined
吗?
{
"webservice_status" : {
"status" : "SUCCESS",
"message" : ""
},
"people_list" : [ {
"people_id" : 001,
"username" : "pxy123",
"full_name" : "James Camerion",
"details_list" : [ {
"id" : 1234,
"name" : "First Hand Details",
"role" : {
"type_id" : 3042,
"people_type" : "SuperUser"
}
} ]
}, {
"people_id" : 002,
"username" : "gbt123",
"full_name" : "Tom Cruise",
"details_list" : [ {
"id" : 1234,
"name" : "First Hand Details",
"role" : {
"type_id" : 3041,
"people_type" : "Normal User"
}
}, {
"id" : 5678,
"name" : "Second Hand Details",
"role" : {
"type_id" : 3042,
"people_type" : "SuperUser"
}
} ]
}, {
"people_id" : 003,
"username" : "txt456",
"full_name" : "Michael Jordon",
"details_list" : [ {
"id" : 1234,
"name" : "First Hand Details",
"role" : {
"type_id" : 3042,
"people_type" : "SuperUser"
}
} ]
}, {
"people_id" : 004,
"username" : "mxn788",
"full_name" : "Paul Walker",
"details_list" : [ {
"id" : 1234,
"name" : "First Hand Details",
"role" : {
"type_id" : 3042,
"people_type" : "SuperUser"
}
} ]
}, {
"people_id" : 005,
"username" : "nhgy234",
"full_name" : "Brad Pitt",
"details_list" : [ {
"id" : 1234,
"name" : "First Hand Details",
"role" : {
"type_id" : 3042,
"people_type" : "SuperUser"
}
} ]
} ]
}