将BSON转换为有效的JSON

Ban*_*San 10 .net c# mongodb bson mongodb-.net-driver

BsonDocument.ToJson()方法返回无效的JSON,因为ObjectID()ISODate是无效的JSON.

从仲裁BSON文档获取有效JSON的最佳方法是什么?

Mai*_*nul 11

你可以尝试这样的事情

var document = new BsonDocument("_id", ObjectId.GenerateNewId());
    var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }; // key part
    Console.WriteLine(document.ToJson(jsonWriterSettings));
Run Code Online (Sandbox Code Playgroud)

详细信息 https://groups.google.com/forum/#!topic/mongodb-user/fQc9EvsPc4k

  • 现在代替`"Property" : NumberDecimal("23.44")` 我得到`"Property" : { "$numberDecimal": "23.44"} ` - 它不能像普通人一样将十进制值放入结果中? 我只想要`“属性”:23.44` (4认同)