I am using table data from jQuery Datatable and passing it to an ajax function. The function calls a web service to process the data and I am stuck trying to deserialize it.
The initial call comes from datatable's 'buttons' button group, where I am trying to implement a custom export to Excel:
buttons: [
{
extend: "collection",
text: "Export",
buttons: [
{
text: 'My Excel',
action: function (e, dt, node, config) {
exportToExcel(dt);
}
},
...
]
function exportToExcel(dt) {debugger
// var tableRows = dt.rows().data().toArray();
var tableRows = dt.data().toArray();
var blah = JSON.stringify({ TableData: tableRows });
$.ajax({
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
cache: false,
url: "../WebService/ABC.asmx/ExportToExcel",
data: JSON.stringify({ TableData: blah }),
}).done(function (result) {
}).fail(...
I tried creating classes to see if that would work but no luck.
public string ExportToExcel(string TableData)
{
string JSONresult = string.Empty;
//Errors_Counts[] oDict = (JsonConvert.DeserializeObject<Dictionary<string, Errors_Counts[]>>(TableData)).Values.FirstOrDefault();
return JSONresult;
}
The data, once JSON-stringified looks like this:
{"TableData":
[
{"THEDATE":"2022-12-10T00:00:00","E38":0,"E39":1,"E40":37,"E41":0,"E42":0},
{"THEDATE":"2022-12-11T00:00:00","E38":0,"E39":0,"E40":20,"E41":0,"E42":0},
...
]
}
How would I deserialize this to end up with a dataset or data table that I can further process? Right now I just have a JSON string. The third party soaftware that I use for exporting to Excel works best with data table. So if I can end up with a data table with column names as TheDate, E38, E39, ... it would solve my issue.