I am trying to parse a JSON file with the exact stucture as in the following.
{
"students": {
"student": [
{
"id": 1,
"name": "John Doe",
"image": "pic1.jpg",
"homepage": "http: //www.google.com"
},
{
"id": 2,
"name": "Jane Doe",
"image": "pic1.jpg",
"homepage": "http: //www.google.com"
}
]
}
}
I am using the following jQuery function:
function GetStudents(filename)
{
$.getJSON(filename, function(data){
$.each(data.student, function(i,s){
var id = s.id;;
var name = s.name;;
var img = s.image;;
var homepage = s.homepage;
$('.networkTable').append('<tr><td><img src="' + img + '" class="picEven pic" width="33" height="35"></td><td><a href="'+ homepage + '" class="networkLink">' + name + '</a></td></tr>');
});
});
}
Is there something I am doing wrong?
$.each(data.students.student,.... Does this help? If not then there might be a problem retrieving the data. Are you reading the file from your server or an external one?$.each(data.students.student, /*other code here...*/);