简体   繁体   English

NewtonSoft JsonConvert.SerializeObject, \" 在序列化 DateTime 后添加

[英]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.

相关问题 JsonConvert.SerializeObject()在使用DateTime字段序列化类时失败 - JsonConvert.SerializeObject() fails in serializing class with DateTime fields NewtonSoft JsonConvert.SerializeObject中的MaxJsonLength错误 - MaxJsonLength error in NewtonSoft JsonConvert.SerializeObject Newtonsoft.Json.JsonReaderException:在 JsonConvert.SerializeObject 之后解析 JsonConvert.DeserializeObject 时遇到意外字符 - Newtonsoft.Json.JsonReaderException: Unexpected character encountered while parsing on JsonConvert.DeserializeObject after JsonConvert.SerializeObject 在 JsonConvert.SerializeObject 中更改日期时间格式 - Change DateTime format in JsonConvert.SerializeObject 如果名称为大写字母,Newtonsoft JsonConvert.SerializeObject会忽略JsonProperty - Newtonsoft JsonConvert.SerializeObject ignoring JsonProperty if name is uppercase Newtonsoft.Json C# :: 格式化 JsonConvert.SerializeObject - Newtonsoft.Json C# :: Formatting JsonConvert.SerializeObject JsonConvert.SerializeObject:序列化空值时出现意外结果 - JsonConvert.SerializeObject: Unexpected result when Serializing null value JsonConvert.SerializeObject使用非空DateTime属性进行分类? - JsonConvert.SerializeObject to class with non-nullable DateTime properties? JsonConvert.SerializeObject转义反斜杠 - JsonConvert.SerializeObject escaping backslash 为什么我不能在wcf服务中使用Newtonsoft.Json JsonConvert.SerializeObject? - Why I can't use Newtonsoft.Json JsonConvert.SerializeObject in wcf service?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM