2016-02-02 40 views

回答

0

是的,只是反序列如下在Deserialize from BSON所述指令類型dynamic(或JTokenExpandoObject):

 dynamic result; 

     using (var stream = new MemoryStream(byteArray)) 
     using (var reader = new BsonReader(stream)) 
     { 
      var serializer = JsonSerializer.CreateDefault(); 
      result = serializer.Deserialize<dynamic>(reader); // Or ExpandoObject or JToken 
     } 

原型fiddle

要直接從一個文件流,使用FileStream

 string path = "bsonData.bson"; // Or whatever 
     dynamic result; 

     using (var stream = File.OpenRead(path)) 
     using (var reader = new BsonReader(stream)) 
     { 
      var serializer = JsonSerializer.CreateDefault(); 
      result = serializer.Deserialize<dynamic>(reader); // Or ExpandoObject or JToken 
     } 
相關問題