Newtonsoft.Json.dll 或者通过-》工具-》库程序包管理工具-》NuGet管理包-》联机 输入Newtonsoft或者json.net
Newtonsoft.Json是可以的:
context.Response.ContentType = "text/plain";
BooksService service = new BooksService();
List<Books> list=service.GetAll().Take(5).ToList();
JsonSerializerSettings setting = new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
};
strintret = JsonConvert.SerializeObject(list, setting);
context.Response.Write(ret);
easyui 代码
$(‘#BooKlist‘).datagrid({
url: ‘BookHandler.ashx?flag=GetBookList‘,
pagination: true,
pageList: [5, 15, 20, 25],
pageSize: 5,
columns: [[
{ field: ‘Title‘, title: ‘书名‘, width: 120 },
{ field: ‘Author‘, title: ‘作者‘, width: 120 },
{ field: ‘ISBN‘, title: ‘ISBN‘, width: 120 },
{
field: ‘Publishersid‘, title: ‘出版社‘, width: 120,
formatter: function (value, row, index) {
return row.Publishers.Name;
}
},
{
field: ‘CategoryId‘, title: ‘书类别‘, width: 120,
formatter: function (value, row, index) {
return row.Categories.Name;
}
}
]]
});
原文地址:https://www.cnblogs.com/wlzhang/p/8994243.html