webapi时间字段返回格式设置及返回model首字母小写

Posted on 2017-03-03 15:55  hwisecn  阅读(656)  评论(0编辑  收藏  举报
 GlobalConfiguration.Configuration.Formatters.Remove(new XmlMediaTypeFormatter());
            // 解决json序列化时的循环引用问题
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling =
                Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            // 对 JSON 数据使用混合大小写。驼峰式,但是是javascript 首字母小写形式.
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.ContractResolver =
                new CamelCasePropertyNamesContractResolver();
            //对日期格式进行统一处理
            GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(
                new IsoDateTimeConverter()
                {
                    DateTimeFormat = "yyyy-MM-dd HH:mm:ss.fff"
                });

 

Copyright © 2024 hwisecn
Powered by .NET 9.0 on Kubernetes