I am trying to parse a JSON feed using LINQ and can't quite wrap a list of objects/values into a reasonable class.
My JSON looks like:
{
"Project":[
{
"ID":"XY1212",
"Name":"Some Name",
"Description":"U.S. No 2 Diesel Retail Prices",
"Manager":"Nora Sims",
"Dept":"HR",
"Updated":"2014-07-22",
"Statistics":[
[
"20140722",
32.22
],
[
"20140721",
55
],
[
"20140720",
343
],
[
"20140519",
43
],
[
"20140421",
3.971
],
[
"20140211",
40.2
],
[
"20140210",
17
],
[
"20140209",
16
]
]
}
]
}
From the above JSON, I have the following class structure:
public class Project
{
public string ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Manager { get; set; }
public string Dept { get; set; }
public string Updated { get; set; }
public List<List<object>> Statistics { get; set; }
}
public class RootObject
{
public List<Project> Project { get; set; }
}
public class Statistic
{
public Datetime ProjectDate { get; set; }
public Decimal Sale { get; set; }
}
I am trying to parse the feed and just want the "Statistics" data, but not sure how to get all of the values into the collection of "Statistics":
HttpClient() http = new HttpClient();
var json = await http.GetStringAsync(uri);
JObject jo = JObject.Parse(json);
var jList = from values in jo["Project"].Children()["Statistics"]
select values;
When I inspect jList via the following loop:
foreach (var stat in jList)
{
Console.WriteLine(stat);
}
I can "see" all of the values, but it only loops once, i.e. jList is only one big [0] with a "value" of all of the [x, y], [x1, y1], ..., i.e. looks like an array of one dimension with many 2D arrays inside it.
I want to loop through all of the "arrays", I believe that's what they are, within the [0] I see in Visual Studio while debugging.
Any advice appreciated.