I have json object in data after ajax call like
[
{
"_id": {
"$id": "58d8e2831d7859e80d000033"
},
"broadcast_id": 70,
"studentList": "",
"employeeList": "999",
"mailTitle": "adsf",
"broadcastMessage": "dsfsdf dsd fgd",
"emailSent": "0",
"userdetails": []
},
{
"_id": {
"$id": "58d8eaba1d7859c81300002e"
},
"broadcast_id": 72,
"studentList": "",
"employeeList": "999|788",
"mailTitle": "Hekjh",
"broadcastMessage": "hhyky jk",
"emailSent": "0",
"userdetails": []
},
{
"_id": {
"$id": "58dde8ed1d78597011000029"
},
"user_id": 1,
"broadcast_id": 76,
"studentList": "",
"employeeList": "999|788",
"mailTitle": "Hello",
"broadcastMessage": "How are u ",
"emailSent": "0",
"dateSent": "31/03/2017",
"userdetails": [
{
"_id": {
"$id": "568f95dc99fbadb016000029"
},
"uid": 1,
"username": "test",
"password": "LeLafe#7861",
"email_id": "[email protected]",
"creation_date": "",
"role": "admin",
"is_enabled": 1
}
]
}
]
Now I am trying parse nested json attribute userdetails in order to role and display it in a table. I have tried following lines
$.ajax({
url: 'index.php?action=fetchBroadcastedMessageList',
type: 'POST',
dataType: 'JSON',
data: { usertype: usertype },
success: function(data) {
for (var i in data) {
$("#broadcastedmessagelist").append('<tr>' +
'<td style="text-align: center;">' +
'' + data[i].userdetails["role"] + '' +
'</td>'...
);
}
});
}
The line data[i].userdetails["role"] does not retrieve corresponding role
value whereever there are userdetails available. Please help me !!!