Deserialize JSON string to Dictionary<string,object>

Solution 1:

See mridula's answer for why you are getting null. But if you want to directly convert the json string to dictionary you can try following code snippet.

    Dictionary<string, object> values = 
JsonConvert.DeserializeObject<Dictionary<string, object>>(json);

Solution 2:

I like this method:

using Newtonsoft.Json.Linq;
//jsonString is your JSON-formatted string
JObject jsonObj = JObject.Parse(jsonString);
Dictionary<string, string> dictObj = jsonObj.ToObject<Dictionary<string, object>>();

You can now access anything you want using the dictObj as a dictionary. You can also use Dictionary<string, string> if you prefer to get the values as strings.