JSON Formatting Error with C# WebMethod

JSON Formatting Error with C# WebMethod

strawlionstrawlion Posts: 2Questions: 0Answers: 0
edited December 2012 in General
Hello, I am getting the following error:

DataTables warning (table id = 'table'); DataTables warning:
JSON data from server could not be parsed. This is caused by a JSON formatting error.

I believe this is because when using a WebMethod in C# the JSON is formatted differently from normal JSON (Everything is wrapped in a d: IE {"d": 42} ).

My code:

JavaScript
[code]
$(document).ready(function () {
$('#table').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "SystemLog.aspx/GetSystemLog"
});
});
[/code]

C#
[code]
[System.Web.Services.WebMethod]
public static string[][] GetSystemLog()
{
return SystemLog.Get2DArray();
}
[/code]


I can successfully store the array of arrays in a javascript variable using a callback function, so I know that the JSON can be parsed and converted correctly outside of the dataTables library. Example:

[code]
var aaData;
function ScriptCallback(result) {
aaData = result;
}
[/code]

The above will correctly store the array of arrays in aaData when calling PageMethods.GetSystemLog(ScriptCallbakc), so I'm not sure why dataTables can't handle this directly?

I am not quite sure how to troubleshoot this error. Can anyone give any insight on this? Thanks!

Replies

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    What does the JSON that is returned look like? Also worth searching the forum as this has come up a number of times before and you'll likely find an asnwer in the other threads.

    Allan
This discussion has been closed.