2009-05-19 97 views
1

我有一个ASP.NET WebService的返回列表的对象webservice的jQuery中返回集合类型

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

} 

我使用这个jQuery代码

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

访问此WebService但我得到的是对象对象。

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

回答

1

一切都是在jQuery中的[对象对象](当你检查一个jQuery对象)。

实际上,您正在获取一个Student对象数组;您可以通过结果这样

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

由于重复这样much..I忘了提,我使用jmsajax而不是$就..所以当我做什么你suggest..i得到d.length为空或不是对象。 – Musa 2009-05-19 12:54:36