本篇文章主要介绍了"MVC web api 返回JSON的几种方式,JSON时间去T的几种方式。",主要涉及到方面的内容,对于.NETjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下:
MVC web api 返回JSON的几种方式1、在WebApiConfig的Register中加入以下代码1 config.Formatters.JsonFo...
MVC web api 返回JSON的几种方式
1、在WebApiConfig的Register中加入以下代码
1 config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
2、在WebApiConfig的Register中加入以下代码
1 config.Formatters.Remove(config.Formatters.XmlFormatter);
3、在WebApiApplication的Application_Start中加入以下代码
1 GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
1、在MVC中全局去除时间格式中带T的问题。
在WebApiConfig的Register中加入以下代码
1 GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new IsoDateTimeConverter
2 {
3 DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
4 });
2、在webservice中去除时间带T的问题。
1 IsoDateTimeConverter timejson = new IsoDateTimeConverter
2 {
3 DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
4 };
5 在序列化的时候传入timejson对象
6 如:
7 return JsonConvert.SerializeObject(object, timejson);//object就是需要序列化的对象
以上就介绍了MVC web api 返回JSON的几种方式,JSON时间去T的几种方式。,包括了方面的内容,希望对.NETjrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。
本文网址链接:http://www.codes51.com/article/detail_107009.html