Handling MongoDB's ISODate() when attempting to parse a serialized JSON string

前端 未结 6 1788
庸人自扰
庸人自扰 2021-02-07 11:00

I\'m using MongoDB via the official C# driver with an ASP.NET MVC web site.

I have the following C# model:

public class Contact
{
    public ObjectId Id          


        
6条回答
  •  无人及你
    2021-02-07 11:28

    You SHOULD use JsonConvert to properly convert the Date to Json. the accepted answer produces a date object like: { $date: 190012312211 } as @Rick Strahl mentioned. This should work:

    object val = BsonTypeMapper.MapToDotNetValue(bsonDocument);
    string jsonString = JsonConvert.SerializeObject(val);
    

提交回复
热议问题