Parsing JSON is just slightly not right coming from .net Json serialzer

Parsing JSON is just slightly not right coming from .net Json serialzer

jumbaliajumbalia Posts: 1Questions: 0Answers: 0
edited February 2012 in General
I have a specific serialization issue, and I hope someone can help

The resulting serialized objects are *slightly* incorrect, and not recognized by datatables as valid.


This is the JSON result

{ "aaData": [
{"engine":"das boot","browser":"das boot","platform":"das boot","version":"das boot","grade":"das boot"},
{"engine":"regulator","browser":"regulator","platform":"regulator","version":"regulator","grade":"regulator"}
]
}


But DataTables wants it like this:

{ "aaData": [
[das boot","das boot","das boot","das boot","das boot"],
["regulator","regulator","regulator","regulator","regulator"]
]
}

I know the issues. Two things are different. The property name is returning as - "engine":"das boot" instead of just "das boot"
But more annoying each row is wrapped in "{ }" instead if "[ ]".

Firebug thinks my Json results are prefect. but Datatables doesn't like it.

So this may be a .NET serialization question in the end.

I'm using MVC and VB.NET

My controller action
_
Function AjaxHandlerForBrowsers(param As JQueryDataTableParamModel) As ActionResult

Using Context As New TFEEntities

Dim daList = Context.JobTasks.Select(Function(job) New mything With {.engine = job.Notes, .browser = job.Notes, .platform = job.Notes, .version = job.Notes, .grade = job.Notes}).ToList
Dim wrapped = New With {.aaData = daList}
Return Json(wrapped, JsonRequestBehavior.AllowGet)

End Using

End Function


Any idea? Thanks for helping out.

Replies

  • allanallan Posts: 63,542Questions: 1Answers: 10,476 Site admin
    DataTables can take input front he first form as well - see this blog post for details: http://datatables.net/blog/Extended_data_source_options_with_DataTables .

    Allan
This discussion has been closed.