Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC4 JSON.Net oob

I have read a few pieces of conflicting information regarding MVC 4's out-of-the-box support for JSON.NET

I gathered that MVC is serializing JSON by default using JSON.NET now, however I still have the tell-tale MS date format in my JSON output.

Is there any bootstrapping that still needs to be done?

Example action:

    //
    // GET: /Test/
    [HttpGet]
    public JsonResult Test()
    {
        return Json(new {date = DateTime.Now}, JsonRequestBehavior.AllowGet);
    }

results in:

{
    "date": "/Date(1355399663508)/"
}
like image 904
jenson-button-event Avatar asked Jun 04 '26 15:06

jenson-button-event


1 Answers

It is using Json.net by default for asp.net web api only.

As per release notes Json.NET: We now use and support the popular Json.NET serializer for handling of JSON data. Json.NET is the default JSON serializer used by ASP.NET Web API and it includes support for data contracts, anonymous types, dynamic types, Dates, TimeSpans, object reference preservation, indenting, camel casing and many other useful serialization features.

like image 182
dove Avatar answered Jun 06 '26 04:06

dove