我假设您正在使用来自http://www.datatables.net/的数据表。如果我错了,请纠正我。
我不确定您是否在创建 JSON 字符串以返回 AJAX 调用或将其转换为服务器端可用的内容时遇到问题。
如果您要在 Web 方法中创建 JSON 字符串,我建议使用 Dictionary 类型,因为它们非常接近 JSON 字符串。要将 Dictionary 类型转换为 JSON 字符串,请使用以下命令:
var dictionary = new Dictionary<string, string>()
// add values here...
return new JavaScriptSerializer().Serialize(dictionary);
如果要将 JSON 字符串转换为 Dictionary 对象,请使用以下命令:
var dictionary = new JavaScriptSerializer().Deserialize<Dictionary<string, string>>(jsonString);
Another thing I like to do is convert the dictionary into an array if I am going to be working with any keys or values since getting them from the dictionary can be a pain when you do not know the exact key value you want to work with.
For reference, the JavaScriptSerializer is part of the System.Web.Script.Serialization.JavaScriptSerializer namespace and in the System.Web.Extensions assembly.