【问题标题】:How to deserialize JSON text to BsonDocument with ISO 8601 formatted DateTime fields?如何使用 ISO 8601 格式的 DateTime 字段将 JSON 文本反序列化为 BsonDocument?
【发布时间】:2016-05-07 18:00:27
【问题描述】:

给定一个包含 ISO8601 格式时间戳字段的 JSON 文本,如下所示

{ "时间戳":"2016-01-29T14:51:52.4338035-06:00", “someKey”:“someVal” }

如何创建具有正确键入字段的 BsonDocument?

我试过了

BsonDocument bsonDocument = BsonSerializer.Deserialize(json);

但是bsonDocument["Timestamp"] 的值的类型是BsonString 而不是BsonDateTime

如果我尝试调用bsonDocument["Timestamp"].AsBsonDateTime,它会抛出InvalidCastException

有什么想法吗?

【问题讨论】:

    标签: c# json mongodb serialization bson


    【解决方案1】:

    使用BsonSerializer.Deserialize<BsonDateTime>(json)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-06-26
      • 2016-01-06
      • 2012-12-11
      • 1970-01-01
      • 2014-12-12
      • 2015-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多