json serialize c# dictionary code example
Example 1: c# serialize json
using System.Text.Json;
var jsonString = JsonSerializer.Serialize(yourObject);
var obj = JsonSerializer.Deserialize<YourObject>(stringValue);
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# json serialize
string jsonString = JsonSerializer.Serialize(weatherForecast);