I have this JSON:
{
"jsonDept": [
{
"Id": "1",
"DeptName": "aaaa "
}, {
"Id": "2",
"DeptName": "bbb "
}, {
"Id": "6",
"DeptName": "ccc "
}, {
"Id": "7",
"DeptName": "ddd "
}, {
"Id": "8",
"DeptName": "eee "
}, {
"Id": "9",
"DeptName": "fff "
}, {
"Id": "12",
"DeptName": "haha "
}, {
"Id": "13",
"DeptName": "test1 "
}, {
"Id": "14",
"DeptName": "test2 "
}, {
"Id": "10",
"DeptName": "tmd "
}, {
"Id": "11",
"DeptName": "tnnd "
}
]
}
And my JQuery:
function loadDepartmentList() {
$.ajax({
url: "QueryDepartment.ashx",
//data: "",
type: "GET",
dataType: 'json',
success: function (data) {
// how to read json here? this is not working
$.each(data, function () {
alert("Name: " + this.DeptName);
});
}
})
}
but alert shows “undefined”, and only popup once.
What I want to do is parse this json, and generate html <ul><li>DeptName</li></ul> and put the html into a div.
I googled many codes, they are not working. I think it may be the problem with the begining string “jsonDept”.
Can anyone write a working script for this json? Thanks!
The returned object contains one property, that is
jsonDept. It is thejsonDeptproperty which contains the array of department information.