I am working on a server and a client, the server is written in C++ and the client is written in C#.
On the client side I am using Newtonsoft's "Json.net" and also the bson from Newtonsoft.
I am trying to send a bson that one of its' keys has multiple values (or a list value) that look something like this:
{
"price": "193"
"cart": ["apple", "banana", "watermelon"]
}
I made a class that I can deserialize the bson into which looks like this:
public class Order
{
public int price {get; set;}
public string[] cart {get; set;}
}
and the deserialization looks like this:
byte[] data; // let's say our bson is in this array
// {
// "price": "193"
// "cart": ["apple", "banana", watermelon"]
//}
MemoryStream ms = new MemoryStream(data);
using (BsonReader reader = new BsonReader(ms))
{
JsonSerializer serializer = new JsonSerializer();
Order o = serializer.Deserialize<Order>(reader);
}
Console.WriteLine(o.cart); // error: cart is null
I took this deserialization code straight from the documentation here.
No matter what I tried, the cart
property always returns as null
.
I tried replacing the string array with a List<string>
but still no luck.
Am I missing something?
edit:
problem solved.
I replaced the BsonReader
to BsonDataReader
and that sloved the problem.