Loop through JSON object List
Be careful, d
is the list.
for (var i = 0; i < result.d.length; i++) { alert(result.d[i].employeename);}
had same problem today, Your topic helped me so here goes solution ;)
alert(result.d[0].EmployeeTitle);
It's close! Try this:
for (var prop in result) { if (result.hasOwnProperty(prop)) { alert(result[prop]); }}
Update:
If your result is truly is an array of one object, then you might have to do this:
for (var prop in result[0]) { if (result[0].hasOwnProperty(prop)) { alert(result[0][prop]); }}
Or if you want to loop through each result in the array if there are more, try:
for (var i = 0; i < results.length; i++) { for (var prop in result[i]) { if (result[i].hasOwnProperty(prop)) { alert(result[i][prop]); } }}