MVC4 JSON.Net oob

时间秒杀一切 提交于 2021-01-27 14:15:24

问题


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)/"
}

回答1:


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.



来源:https://stackoverflow.com/questions/13859321/mvc4-json-net-oob

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!