How to deserialize JSON array into array of .NET objects

May 2, 2010 at 3:24 PM

How would i take a json string like this:

{"count":3,"items":[{"id":"4","priority":"3","subject":"Another message","message":"adsfasdf"},
{"id"
:"2","priority":"3","subject":"testing again","message":"just seeing ow "},
{"id":"7","priority":"3","subject"
:"asdgasdg","message":"asdfasdfasd"}]}

and turn it into a .NET class holding items as an array of Items classes?
Coordinator
May 3, 2010 at 12:22 AM

Simplest solution would be to create a class like this:

 

public class ItemContainer

{

  public int Count { get; set; }

  public IList<Item> Items { get; set; }

}

 

Deserialize to that and then get the collection of items from the Items property.

May 3, 2010 at 2:03 AM

How would the attributes need to be for deserialization? Also, other than the documentation provided, is there any place to learn how to use JSON.Net? The documentation wasn't really helpful in learning it. I actually really don't know what i'm doing at all. :-(