我有这个 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 "
}
]
}
还有我的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);
});
}
})
}
但警报显示“未定义”,并且只弹出一次。
我想要做的是解析这个json,生成html<ul><li>DeptName</li></ul>
并将html放入一个div。
我用谷歌搜索了很多代码,它们都不起作用。我认为这可能是开头字符串“jsonDept”的问题。
任何人都可以为这个 json 编写一个工作脚本吗?谢谢!