Click or drag to resize
Json.NET

Deserialize from BSON

 

This sample deserializes BSON to an object.

Sample
Types
public class Event
{
    public string Name { get; set; }
    public DateTime StartDate { get; set; }
}
Usage
byte[] data = Convert.FromBase64String("MQAAAAJOYW1lAA8AAABNb3ZpZSBQcmVtaWVyZQAJU3RhcnREYXRlAMDgKWE8AQAAAA==");

MemoryStream ms = new MemoryStream(data);
using (BsonReader reader = new BsonReader(ms))
{
    JsonSerializer serializer = new JsonSerializer();

    Event e = serializer.Deserialize<Event>(reader);

    Console.WriteLine(e.Name);
    // Movie Premiere
}