I'm trying to deseralize some json into a collection (list), but I'm not sure which method will return a list of objects, or do I have to loop through something and copy it to my own list?
Can anyone tell me the syntax or method I should use for this.
I've created my object with some properties, so it's ready to be used to hold the data. (title,url,description)
I've tried this, but it doesn't seem quite right
List<newsItem> test = (List<newsItem>)JsonConvert.DeserializeObject(Fulltext);
Did you try looking at the help?
http://james.newtonking.com/json/help/?topic=html/SerializingCollections.htm
string json = @"[
{
""Name"": ""Product 1"",
""ExpiryDate"": ""\/Date(978048000000)\/"",
""Price"": 99.95,
""Sizes"": null
},
{
""Name"": ""Product 2"",
""ExpiryDate"": ""\/Date(1248998400000)\/"",
""Price"": 12.50,
""Sizes"": null
}
]";
List<Product> products = JsonConvert.DeserializeObject<List<Product>>(json);
Console.WriteLine(products.Count);
// 2
Product p1 = products[0];
Console.WriteLine(p1.Name);
// Product 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With