在webapiConfig.cs
加上以下代码作为配置:
//实现序列化为JSON
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new IsoDateTimeConverter {
DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
});
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
new CamelCasePropertyNamesContractResolver();
Controller调用:
return Json<dynamic>(new {
success = true,
msg = "OK",
profits = mypf
}, GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings);