jQuery中的webservice返回集合类型

时间:2009-05-19 12:32:57

标签: asp.net jquery

我有一个ASP.NET WebService,它返回List的对象

public class Students
{
    public string StudentName { get; set; }
     public int Age { get; set; }

}

我正在使用此jQuery代码访问此Web服务

$.ajax({
type: "POST",
url: "/Students.asmx/GetStudents",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) { 
$("#myDiv").html(msg.d);
}
});

但我得到的只是Object对象。

如何获取该对象中的数据?

1 个答案:

答案 0 :(得分:1)

jquery中的所有东西都是[Object object](当你检查jQuery对象时)。

您实际上正在获取一组Student对象;你可以像这样迭代结果

for (x = 0; x < msg.length; x++) {
    alert(msg[x].StudentName);
}
相关问题