首先需要引用Newtonsoft.Json
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
然后转换对象
Model.JsonResult jsonResult = new Model.JsonResult
{
State = 200,
Message = "success",
Data = dt.ToList()
};
string json = JsonConvert.SerializeObject(
jsonResult,
Formatting.Indented,
new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
});
输出的JSON字符串
{
"message": "success",
"state": 200,
"data": [],
"script": ""
}
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。