Valid Json
Valid Json
I'm going to reference this first off:
http://datatables.net/forums/comments.php?DiscussionID=828
Going to http://www.jsonlint.com/ with the following:
[code]
[
{
"ID": "15",
"FirstName": "Black",
"Email": "martha@domain.com"
},
{
"ID": "15",
"FirstName": "Black",
"Email": "martha@domain.com"
}
]
[/code]
Basically what I'm seeing in DataTables is that you cannot have this valid json, that it requires a non-standard (?) parsing of Json ?
I'm curious why the DataTable cannot accept this valid json - it seems like a hack to do what the above link is suggesting ?
Thanks
http://datatables.net/forums/comments.php?DiscussionID=828
Going to http://www.jsonlint.com/ with the following:
[code]
[
{
"ID": "15",
"FirstName": "Black",
"Email": "martha@domain.com"
},
{
"ID": "15",
"FirstName": "Black",
"Email": "martha@domain.com"
}
]
[/code]
Basically what I'm seeing in DataTables is that you cannot have this valid json, that it requires a non-standard (?) parsing of Json ?
I'm curious why the DataTable cannot accept this valid json - it seems like a hack to do what the above link is suggesting ?
Thanks
This discussion has been closed.
Replies
You are quite right in that my comment could be taking in the wrong light - DataTables does require valid JSON, and accepts it, but only accepts a sub-set of what is possible with JSON. Specifically what DataTables is looking for is a 2D array of data which can be put into the table.
It probably would be possible to add support for the data format you have above, however adding support for that type would lead to adding other types and so on. As such I prefer to keep only one standard type supported in the core, and other options can be very readily added using fnServerData.
So two options - either you could change your formatting to a simple 2D array, which is easier if you are just echoing data, but I guess you are using a JSON parser, so fnServerData as a data pre-processor is possibly the way to go. Something like:
[code]
var aNew = [];
for ( var i=0, iLen=aOrig.length ; i
Steve