Why has JSON.NET default DateTime serialization changed?

后端 未结 3 1699
离开以前
离开以前 2021-01-07 19:20

I\'ve been using an old version of JSON.Net (4.0r4) for a while & have just updated to the latest one (4.5r11). I\'ve noticed that dates used to be formatted like:

3条回答
  •  醉话见心
    2021-01-07 20:15

    If you have UTC data on server you should explicitly set DateTimeZoneHandling property

     //serializer fix
            config.Formatters.Clear();
            config.Formatters.Add(new JsonMediaTypeFormatter()
            {
                SerializerSettings = new JsonSerializerSettings() {
                    ContractResolver=new CamelCasePropertyNamesContractResolver(),
                    DateTimeZoneHandling = DateTimeZoneHandling.Utc},
    
            });
    

    After this DateTime has "Z" at the end: 2017-05-11T00:35:20.8242381Z

提交回复
热议问题