首页 > Windows开发 > 详细

WebApi关于配置全局返回Json数据格式时间以及命名小写

时间:2017-01-20 17:56:04      阅读:1045      评论:0      收藏:0      [点我收藏+]

1.直接在Global文件中配置:

技术分享
  1 var formatters = GlobalConfiguration.Configuration.Formatters;
  2 var jsonFormatter = formatters.JsonFormatter;
  3 var settings = jsonFormatter.SerializerSettings;
  4 settings.Formatting = Newtonsoft.Json.Formatting.Indented;
  5 settings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
  6 settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
View Code
技术分享

技术分享

2.配置任意的返回格式json和xml

技术分享
  1config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("format", "json", "application/json"));
  2config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("format", "xml", "application/xml"));
View Code

技术分享

3.使用Cors跨域框架配置跨域

技术分享

3.1在webapi控制器下的配置

技术分享

WebApi关于配置全局返回Json数据格式时间以及命名小写

原文:http://www.cnblogs.com/M-LittleBird/p/6323147.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!