了Methode在Web服務jsonArray未示出(web服務)
了Methode:
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = true)]
public void GetList()
{
JavaScriptSerializer ser = new JavaScriptSerializer();
Test[] test=new Test[3];
test[0] = new Test("1", "anex");
test[1] = new Test("2", "Ahmed");
test[2] = new Test("3", "Karim");
var json = new
{
list=test ,
DateTime=DateTime.Now.ToShortDateString()
};
HttpContext.Current.Response.Write(ser.Serialize(json));
}
結果:{"list":[{},{},{}],"DateTime":"03/10/2016"}
列表不顯示!!
請添加'測試'類的定義。如果它沒有屬性或只有私有屬性,那麼串行器將忽略它們。 –
public class Test { private string id {get;組; } 私人字符串名稱{get;組; } public Test(){} public Test(String i,String n) { this.id = i; this.name = n; } } –
謝謝@rboe它的工作就像一個魅力 –