The closest solution to what I was looking for is this thread How to flatten nested objects with linq expression
But I get an error trying that approach
The type arguments for method 'System.Linq.Enumerable.SelectMany(System.Collections.Generic.IEnumerable, System.Func>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
My code:
var aa = t.data.SelectMany(x =>
x.Value.innerData.SelectMany(y => new { /*Error at this SelectMany*/
url = x.Key,
disp = x.Value.disp,
date = y.Key,
count = y.Value.count,
rank = y.Value.rank,
}));
My classes:
public class TData {
public Dictionary<string, TDetail> data { get; set; }
}
public class TDetail {
public string disp { get; set; }
[Newtonsoft.Json.JsonProperty("data")]
public Dictionary<string, Metrics> innerData { get; set; }
}
public class Metrics {
public string count { get; set; }
public string rank { get; set; }
}
The JSON I get from a 3rd party API looks like below:
{
"data": {
"abc.com": {
"disp": "#712176",
"data": {
"2015-02-08": {
"count": 4,
"rank": 5.8
},
"2015-02-23": {
"count": 3,
"rank": 8.3
},
"2015-03-14": {
"count": 5,
"rank": 3.7
}
}
},
"nbc.com": {
"disp": "#822176",
"data": {
"2015-02-08": {
"count": 3,
"rank": 5.5
},
"2015-02-23": {
"count": 5,
"rank": 8.4
},
"2015-03-14": {
"count": 7,
"rank": 4.7
}
}
}
}
}
How do I specify the type arguments explicitly in this case? Thanks.