Quantcast
Channel: How can I deserialize JSON to a simple Dictionary in ASP.NET? - Stack Overflow
Viewing all articles
Browse latest Browse all 23

Answer by Falko for How can I deserialize JSON to a simple Dictionary in ASP.NET?

$
0
0

I just needed to parse a nested dictionary, like

{"x": {"a": 1,"b": 2,"c": 3    }}

where JsonConvert.DeserializeObject doesn't help. I found the following approach:

var dict = JObject.Parse(json).SelectToken("x").ToObject<Dictionary<string, int>>();

The SelectToken lets you dig down to the desired field. You can even specify a path like "x.y.z" to step further down into the JSON object.


Viewing all articles
Browse latest Browse all 23

Trending Articles