3

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)/"
}
dove
  • 20,469
  • 14
  • 82
  • 108
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155
  • It's kinda duplicated.Please look at this Q:ASP.NET MVC JsonResult Date Format http://stackoverflow.com/a/726869/105445 – Wahid Bitar Dec 13 '12 at 12:08
  • @wahid, not really...if I can hook in JSON.Net i can specify my own date formats...and my question is about proclaimed oob support for JSON.NET in MVC 4 (now answered for me below) and my confusion is now cleared. – jenson-button-event Dec 13 '12 at 12:13

1 Answers1

3

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.

dove
  • 20,469
  • 14
  • 82
  • 108
  • OK, so I still need to go with one of these 2? http://code.msdn.microsoft.com/Using-JSONNET-with-ASPNET-b2423706 or http://www.west-wind.com/weblog/posts/2012/Mar/09/Using-an-alternate-JSON-Serializer-in-ASPNET-Web-API – jenson-button-event Dec 13 '12 at 12:13
  • seems so, with an api project you can set the jsonformatter you want through GlobalConfiguration but can't see a similar hook in a mvc project. I'd probably use your own json result if you can't find a way to set json.net as the default for mvc – dove Dec 13 '12 at 12:28