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"}
一覧!
'Test'クラスの定義を追加してください。プロパティがないかプライベートなものしかない場合、シリアライザはそれらを無視します。 –
パブリッククラスTest { プライベート文字列ID {取得します。セット; } プライベート文字列名{取得します。セット; } public Test(){} public Test(String i、String n) { this.id = i; this.name = n;それは魔法のように –
おかげで、それはAne'xBm @ –