當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
MVC web api 返回JSON的几种方式,Newtonsoft.Json序列化日期时间去T的几种方式
生活随笔
收集整理的這篇文章主要介紹了
MVC web api 返回JSON的几种方式,Newtonsoft.Json序列化日期时间去T的几种方式
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
MVC web api 返回JSON的幾種方式,Newtonsoft.Json序列化日期時間去T的幾種方式
2015-01-18 00:11?https://www.muhanxue.com/essays/2015/01/8623699.html
MVC web api 返回JSON的幾種方式
1、在?WebApiConfig的?Register中加入以下代碼
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));2、在?WebApiConfig的?Register中加入以下代碼
config.Formatters.Remove(config.Formatters.XmlFormatter);3、在?WebApiApplication的?Application_Start中加入以下代碼
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();在MVC中全局去除時間格式中帶T的問題。
1、MVC中默認使用Newtonsoft.Json序列化的,所以在?WebApiConfig的?Register中加入以下代碼即可
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new IsoDateTimeConverter {DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" });2、在?webservice中去除時間帶T的問題。
IsoDateTimeConverter timejson = new IsoDateTimeConverter {DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss" }; //在序列化的時候傳入timejson對象 return JsonConvert.SerializeObject(object, timejson); // object是需要序列化的對象轉載于:https://www.cnblogs.com/Jeely/p/10959008.html
總結
以上是生活随笔為你收集整理的MVC web api 返回JSON的几种方式,Newtonsoft.Json序列化日期时间去T的几种方式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 银行账户备案什么意思?
- 下一篇: JavaScript方法——call和a