问题描述
求助啊怎么生成这样格式的的JSON数据呢我用的是.netwebapi用服务器jquerydatatables插件分页必须要这样的格式{"draw":1,"recordsTotal":57,"recordsFiltered":57,"data":[["Airi","Satou","Accountant","Tokyo","28thNov08","$162,700"],["Angelica","Ramos","ChiefExecutiveOfficer(CEO)","London","9thOct09","$1,200,000"],["Ashton","Cox","JuniorTechnicalAuthor","SanFrancisco","12thJan09","$86,000"],["Bradley","Greer","SoftwareEngineer","London","13thOct12","$132,000"],["Brenden","Wagner","SoftwareEngineer","SanFrancisco","7thJun11","$206,850"],["Brielle","Williamson","IntegrationSpecialist","NewYork","2ndDec12","$372,000"],["Bruno","Nash","SoftwareEngineer","London","3rdMay11","$163,500"],["Caesar","Vance","Pre-SalesSupport","NewYork","12thDec11","$106,450"],["Cara","Stevens","SalesAssistant","NewYork","6thDec11","$145,600"],["Cedric","Kelly","SeniorJavascriptDeveloper","Edinburgh","29thMar12","$433,060"]]}
解决方案
解决方案二:
拼接字符串。
解决方案三:
引用1楼apollokk的回复:
拼接字符串。
不行啊我用的webapi不是aspx求解啊给个代码吧
解决方案四:
不管用户什么你总要获取数据的,获取数据后怎么处理都可以了
解决方案五:
publicclassdemoClass{publicintdraw{setget}publicintrecordsTotal{setget}publicintrecordsFiltered{setget}publicstring[]data{setget}}你将上面的类实例化赋值然后用Newtonsoft.Json将上面的类序列化为json看看格式对不对
解决方案六:
获得到数据后把你的数据拆开然后重新组装成你要的样式不就好了。
解决方案七:
{draw=1,recordsTotal=57,recordsFiltered=57,data=list}这样不行吗?
解决方案八:
用类来包含呗,4L已经给你类定义了引用4楼moonwrite的回复:
publicclassdemoClass{publicintdraw{setget}publicintrecordsTotal{setget}publicintrecordsFiltered{setget}publicstring[]data{setget}}你将上面的类实例化赋值然后用Newtonsoft.Json将上面的类序列化为json看看格式对不对
解决方案九:
手动拼接或者封装成类转换都可以吧
解决方案十:
publicclassDataTables{publicintdraw{get;set;}publicintrecordsTotal{get;set;}publicintrecordsFiltered{get;set;}publicIEnumerable<TestData>data{get;set;}}publicclassTestData{publicintId{get;set;}publicstringName{get;set;}}publicActionResultDataTablesList(){操作完数据后returnJson(DataTables);}