2

Both "array" and "objects" may be not quite the proper terminology here, but I'm sure you got my continental drift.

I see this example for serializing/deserializing a custom object from the official docs:

 product.Name = "Apple";
 product.ExpiryDate = new DateTime(2008, 12, 28);
 product.Price = 3.99M;
 product.Sizes = new string[] { "Small", "Medium", "Large" };

 string output = JsonConvert.SerializeObject(product);
 //{
//  "Name": "Apple",
//  "ExpiryDate": "2008-12-28T00:00:00",
//  "Price": 3.99,
//  "Sizes": [
//    "Small",
//    "Medium",
//    "Large"
//  ]
//}

Product deserializedProduct = JsonConvert.DeserializeObject<Product>(output);

But I need to deserialize an "array" of objects-as-JSON elements, something like:

IEnumerable<Platypus> deserializedProduct = JsonConvert.DeserializeObject<Platypus>(output);

...or:

List<Platypus> deserializedProduct = JsonConvert.DeserializeObject<Platypus>(output);

What is needed on the right side, the JsonConvert/JSON.NET side, to accomplish this?

1
  • 2
    JsonConvert.DeserializeObject<List<SomeType>>(...) Commented Dec 11, 2013 at 20:33

1 Answer 1

7

Why not something like this:

List<Product> deserializedProduct = JsonConvert.DeserializeObject<List<Product>>(object);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.