Try adding [DataContract]
to your class declaration. Also change the type of the CreatedAt
property from string
to DateTime
:
[DataContract]
public class ViewItem
{
[DataMember(Name = "title")]
public string Title { get; set; }
[DataMember(Name = "created_at")]
public DateTime CreatedAt { get; set; }
}
With these changes (and the fix to the JSON), it works for me:
string json = @"[{""created_at"":""2014-03-05T10:26:12Z"",""title"":""task 4""},{""created_at"":""2014-03-05T10:26:12Z"",""title"":""task 5""}]";
List<ViewItem> list = JsonConvert.DeserializeObject<List<ViewItem>>(json);
foreach (ViewItem item in list)
{
Console.WriteLine("Title: " + item.Title);
Console.WriteLine("CreatedAt: " + item.CreatedAt);
}
Output:
Title: task 4
CreatedAt: 3/5/2014 10:26:12 AM
Title: task 5
CreatedAt: 3/5/2014 10:26:12 AM