Json.Net IsoDateTimeConverter不工作 [英] Json.Net IsoDateTimeConverter is not working
问题描述
我在asp.net mvc的做了一个Web应用程序4
I have a web application made in asp.net mvc 4
在Global.asax中,加入我加入 IsoDateTimeConverter
in Global.asax, i added added IsoDateTimeConverter
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
new IsoDateTimeConverter { DateTimeFormat = "dd-MM-yyyy hh:mm" });
}
我有一个ActionResult
I have an ActionResult
public ActionResult GetDate()
{
DateTime dateTime = DateTime.Now;
return Json(dateTime, JsonRequestBehavior.AllowGet);
}
不过,这的ActionResult返回这样的:
However, this actionResult returns this:
"\/Date(1365060823129)\/"
我所缺少的?
推荐答案
好吧,我相信你得到了由所有的不是precise的命名弄得有点其中很多人已最近使用。在 JsonFormatter
(和一般的格式化)所使用的的ASP.NET Web API 的
Well I believe you got a little bit confused by all the "not precise" naming which lot of people have been using lately. The JsonFormatter
(and formatters in general) is used by ASP.NET Web API.
您未使用的的ASP.NET Web API 的,你正在使用的 ASP.NET MVC 4 的(这是完全分开的技术)。
You are not using ASP.NET Web API, you are using ASP.NET MVC 4 (those are completely separated technologies).
在 ASP.NET MVC 4 的序列化的逻辑仍然在 JsonResult
与的JavaScriptSerializer $ C完成$ C>,格式化这里不适用。
In ASP.NET MVC 4 the serialization logic is still done inside the JsonResult
with JavaScriptSerializer
, formatters are not applied here.
如果你想使用的 Json.NET 的(其 IsoDateTimeConverter
)使用的 ASP.NET MVC 4 的你还需要创建自己的的ActionResult
描述的这里。
If you want to use Json.NET (and its IsoDateTimeConverter
) with ASP.NET MVC 4 you still need to create your own ActionResult
as described here.
这篇关于Json.Net IsoDateTimeConverter不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!