My JSON looks like this:
{"2013" : [
{ "date":"2013-01-09 12:00:00","height":0 },
{ "date":"2013-01-19 12:00:00","height":3 },
{ "date":"2013-01-29 12:00:00","height":2 }],
"2012" : [
{ "date":"2012-02-09 12:00:00","height":0 },
{ "date":"2012-02-19 12:00:00","height":4 },
{ "date":"2012-02-29 12:00:00","height":2 }],
"2011" : [
{ "date":"2011-03-09 12:00:00","height":3 },
{ "date":"2011-03-19 12:00:00","height":8 },
{ "date":"2011-03-29 12:00:00","height":2 }]
}
What I am trying to do is get all of the dates and height, but I am only able to do it per year using this code:
public class Report
{
public DateTime Date { get; set; }
public int Height { get; set; }
}
JObject data = JObject.Parse(sr);
var postTitles = from p in data["2013"]
select new Report
{
Date = DateTime.Parse((string)p["date"]),
Height = (int)p["height"]
};
I was thinking of using a for loop but trying a variable inside data[" "] won't work. I was also thinking of doing var postTitles += statement but it is not allowed as well. Any ideas on how I should go about this? I am using JSON.NET and it is suggested that I do a class per year (i.e. 2013, 2012, 2011) but I want them under one class to make it easier to manipulate data.