【发布时间】:2018-09-27 15:10:57
【问题描述】:
我正在寻找答案,但没有任何帮助,所以我再次发布问题,希望有人可以帮助我。 假设我有一个像这样的简单 JSON 字符串:
[
{
"id": 1,
"name": "A"
},
{
"id": 2,
"name": "B"
}
]
这是我将 JSON 解析为 BsonDocument 的代码
using (var jsonreader = new JsonReader(json_data))
{
var context = BsonDeserializationContext.CreateRoot(jsonreader);
//Bson Array, how to deserialize???
var document = collection.DocumentSerializer.Deserialize(context);
collection.InsertOne(document);
}
它将返回错误“System.FormatException: 'Cannot deserialize a 'BsonDocument' from BsonType 'Array'.'
【问题讨论】: