returning data from ASP.NET Ajax pagemethod in JSON
Posted on 2010-01-12
I read that it's not easy to serialize a datatable to JSON.
First question - Do pagemethods return JSON-serializable data in JSON by default? E.g if a pagemethod returns a C# array, will we have to write code in that pagemethod to serialize it to JSON?
If the answer to the above question is yes, I would like to convert the data in my 2-column datatable to a C# object which won't require me to write code for JSON serialization. The data in this datatable is pretty simple. The first column and the second column have one-to-many relationship, which means a single value in the first column has multiple values in the second column.
So from the pagemethod, I can return data in a hashtable or a 2-dimensional array, instead of the actual datatable.