c# json to dictionary code example
Example 1: c# json to dictionary
string json = @"{""key1"":""value1"",""key2"":""value2""}";
var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
Example 2: c# newtonsoft serialize dictionary to json
Dictionary<string, int> points = new Dictionary<string, int>
{
{ "James", 9001 },
{ "Jo", 3474 },
{ "Jess", 11926 }
};
string json = JsonConvert.SerializeObject(points, Formatting.Indented);
Console.WriteLine(json);
Example 3: c# convert object to json
var jsonString = JsonConvert.SerializeObject(ObjectModel);
Example 4: deserialize object to dictionary c#
string json = @"{""key1"":""value1"",""key2"":""value2""}";
var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);