MVC web api returns several ways of JSON, Newtonsoft.Json date and time sequence of several ways to T
2015-01-18 00:11 https://www.muhanxue.com/essays/2015/01/8623699.html
MVC web api return JSON in several ways
1, in WebApiConfig
the Register
the following code is added
config.Formatters.JsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/html"));
2, in WebApiConfig
the Register
adding the following codes
config.Formatters.Remove(config.Formatters.XmlFormatter);
3, in WebApiApplication
the Application_Start
add the following code
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
In MVC global problem of removing time format tape T.
1, MVC Newtonsoft.Json using default serialization, so in WebApiConfig
the Register
adding the following code can be
GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings.Converters.Add(new IsoDateTimeConverter
{
DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
});
2, in webservice
the problem of removing the tape T time.
IsoDateTimeConverter timejson = new IsoDateTimeConverter
{
DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
};
//在序列化的时候传入timejson对象
return JsonConvert.SerializeObject(object, timejson); // object是需要序列化的对象