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" ]
    ]
}
1
  • See generated class(es) at json2csharp.com (the array part is a List<List<string>>, or similar) Commented Nov 30, 2013 at 20:16

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

This is a List<List, not a List<
i must use c# library only
you may want to check this post to. There are two options mentioned for built in json serializtion stackoverflow.com/questions/3275863/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.