Pregunta

How can i create a json array like this in ashx handler:

{ 
    "sEcho": 1, 
    "iTotalRecords": "57", 
    "iTotalDisplayRecords": "57", 
    "aaData": 
    [
         [ "Gecko", "Firefox 1.0", "Win 98+ / OSX.2+", "1.7", "A" ]
    ]
}
¿Fue útil?

Solución

Build it as anonymous object in dotnet and then serialize it as Json, Asp.Net has the serializer built in.

string json = context.Response.Write(Json(new { 
    sEcho = 1, 
    iTotalRecords = "57", 
    iTotalDisplayRecords = "57", 
    aaData = new List<List<String>>
    { new List<String>{ "Gecko", "Firefox 1.0", "Win 98+ / OSX.2+", "1.7", "A" }}
}, JsonRequestBehavior.AllowGet));

Update:

Modified based on comments.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top