I am trying to get data from a Mixpanel API. The JSON result looks like this:
{"computed_at": "2019-11-19T10:36:33.908802+00:00", "legend_size": 1, "data": {"series": ["2019-11-11", "2019-11-12", "2019-11-13"], "values": {"page views": {"2019-11-12": 111, "2019-11-11": 573, "2019-11-13": 209}}}}
I am struggling with nested JSON (despite looking at a fair few StackOverflow articles on this) and I want to try and get the values 111
,573
and 209
for the page views. How do I access these values?
I've tried the following:
var result = {"computed_at": "2019-11-19T10:36:33.908802+00:00", "legend_size": 1, "data": {"series": ["2019-11-11", "2019-11-12", "2019-11-13"], "values": {"page views": {"2019-11-12": 111, "2019-11-11": 573, "2019-11-13": 209}}}}
var rawData = result["data"]["values"]["page views"][0]
but this doesn't work and I can't figure out how to access the individual values. Can anyone help please?
EDIT:
When using the json to C# converter (as suggested in the comments to this post) the outcome is as follows:
public class PageViews
{
public int __invalid_name__2019-11-20 { get; set; }
public int __invalid_name__2019-11-19 { get; set; }
}
public class Values
{
public PageViews __invalid_name__page views { get; set; }
}
public class Data
{
public List<string> series { get; set; }
public Values values { get; set; }
}
public class RootObject
{
public DateTime computed_at { get; set; }
public int legend_size { get; set; }
public Data data { get; set; }
}
and I am still unsure how to get the numbers from this?