Deserializing JSON with dynamic keys

Seriously, no need to go down the dynamic route; use

var deser = new JavaScriptSerializer()
    .Deserialize<Dictionary<string, Dictionary<string, int>>>(val);
var justDaily = deser["daily"];

to get a dictionary, and then you can e.g.

foreach (string key in justDaily.Keys)
    Console.WriteLine(key + ": " + justDaily[key]);

to get the keys present and the corresponding values.

Leave a Comment