gpt4 book ai didi

c# - 如果 DateTime 为 NULL,则无法获取 JSON 响应

转载 作者:太空宇宙 更新时间:2023-11-03 13:25:17 25 4
gpt4 key购买 nike

我有sql数据库。在 sql 中,列类型是 datetime 可为 null,但在 c# 中,实体仅定义为 datetime。

如果 dateTime 为空,则 xml 格式的响应没有问题,但 json 格式的响应会出现问题。如果我将 datetimes 更改为 datetime? 响应,因为 json 格式有效,但它会以不好的方式影响其他实体。

我该如何解决这个问题?谢谢。

最佳答案

我认为问题在于 json 序列化程序将日期发送为 0001-01-01T00:00:00 UTC,当您从处于 UTC 之前时区的计算机反序列化它时可能会产生问题。

试试这个线程中的解决方案,看看它是否有帮助: Why can DateTime.MinValue not be serialized in timezones ahead of UTC?

关于c# - 如果 DateTime 为 NULL,则无法获取 JSON 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22628374/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com