2009-05-19 100 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