0
在ASP.NET的Web API控制器我使用JsonResults這樣的:設置Api.Controller.Json功能使用全局SerializerSettings
return Json(data);
我在WebApiConfig設置全局默認值,因爲我發現在很多地方建議。
HttpConfiguration config = GlobalConfiguration.Configuration;
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new StringEnumConverter());
我以爲這會使設置被使用,但事實並非如此。要解決它我打電話:
return Json(data, GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings);
這工作正常,但我缺少的東西,使全球序列化設置應用所有的時間?