I am trying to parse a JSON result with AJAX.
My JSON looks like this
[{
"_id" : "54fb09b7d059bdf3107f9486",
"lastName" : "Record",
"firstName" : "First",
"__v" : 0
}, {
"_id" : "54fb0a2fd059bdf3107f9487",
"lastName" : "Record",
"firstName" : "First",
"__v" : 0
}
]
I call this in Javascript
$.getJSON('api/people', function(data) {
item3="+data.item3+"</p>");
$.each(data,function(i,j){
content ='<span>'+j[i].firstName+'<br />'+j[i].lastName+'<br /></span>';
});
alert(content);
});
Unfortunately I get "Uncaught TypeError: Cannot read property 'firstName' of undefined" in the console.
Can someone please tell me how to properly parse this JSON?