[英]NewtonSoft JsonConvert.SerializeObject, \" added after serializing DateTime
After serializing a datetime property with NewtonSoft, the value went from 2021-02-19 10:00
as DateTime to \\"2021-02-19T10:00:00\\"
as string.使用 NewtonSoft 序列化 datetime 属性后,值从 2021-02-19
2021-02-19 10:00
作为 DateTime 变为\\"2021-02-19T10:00:00\\"
作为字符串。 Deserializing failed without replacing those \\"
. This replace was a quick fix, but now am I curious how this is possible and how I can avoid the replace.反序列化失败而没有替换那些
\\"
。这个替换是一个快速修复,但现在我很好奇这怎么可能以及如何避免替换。
When things are missing in my post, please give me a comment.当我的帖子中缺少内容时,请给我评论。
Instead of serializing a DateTime
with JsonConvert
, you can use one of the standard format strings.您可以使用标准格式字符串之一,而不是使用
JsonConvert
序列化DateTime
。 The equivalent format to the one the Serialize
method produces is the sortable specifier, s
.与
Serialize
方法产生的等效格式是可排序说明符s
。 So:所以:
new DateTime(2021, 2, 19, 10, 0, 0).ToString("s")
produces:产生:
2021-02-19T10:00:00
without the quotes.没有引号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.