1

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" ]
    ]
}
Oliver Vogel
  • 1,988
  • 1
  • 20
  • 33
Severiano
  • 1,083
  • 3
  • 25
  • 54
  • See generated class(es) at http://json2csharp.com/ (the array part is a `List>`, or similar) – Tim S. Nov 30 '13 at 20:16

1 Answers1

4

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.

Rudy
  • 2,323
  • 1
  • 21
  • 23