Ane'x Bm Ane'x Bm - 2 months ago 21
JSON Question

jsonArray not showing (web service)

Methode in web Service

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));
}


Result :
{"list":[{},{},{}],"DateTime":"03/10/2016"}


List not showing !!

Answer

The Test class does contain private fields only. Therefore the JavaScriptSerializer will ignore them. Declare them as public an they will show up in the produced JSON.