using Newtonsoft.Json; // ... MyClass obj = new MyClass(); string json = JsonConvert.SerializeObject(obj); Console.WriteLine(json);
using Newtonsoft.Json; // ... string jsonString = "{ \"name\": \"John Doe\", \"age\": 30 }"; MyClass obj = JsonConvert.DeserializeObjectIn this example, we have a JSON formatted string and we deserialize it into a MyClass object using the JsonConvert.DeserializeObject method. We then print the Name and Age properties of the resulting object to the console. Package library: Newtonsoft.Json.(jsonString); Console.WriteLine("Name: " + obj.Name); Console.WriteLine("Age: " + obj.Age);