以下代码:
var data = _context.People.ToList(); //_context is my DataContext.
产生结果:
[{ "name": "john", "age": "30" }, { "name": "jane", "age": "31" }]
但是,我希望它是一本字典,所以像:
{ "xldata" : [{ "name": "john", "age": "30" }, { "name": "jane", "age": "31" }] }
我通过以下方式让它工作:
Dictionary<string,List<People>> vals = new Dictionary<string, List<People>>();
vals.Add("xldata", people);
System.Object[]
但是,我的字典的值是people
这样做的目的是导出数据,所以当我到达这一行时:
var people = jss.Deserialize<List<People>>(args["xldata"]);
args["xldata"] is `System.Object[]` and it says `Invalid JSON primitive`.
这是应该将数据导出到excel的脚本:
$.post(urlContent + exportHandlerPath, Json, function(data) {
var viewData = {};
viewData.xldata = JSON.stringify(data);
html = ich.excelExportTemplate(viewData);
$excelExportContainer.html(html);
var input = $excelExportContainer.find('input#excelExportHiddenField');
input.val(viewData.xldata);
var $excelForm = $('#excelExportForm');
$excelForm.attr('action', '/People/ExportToExcel/');
$excelForm.submit();
}