"if youre using System.Text.Json extention"
1. Serialize allows you to convert objects to a json format string:
string defaultPerson = JsonSerializer.Serialize(new Person{
age = 28,
nationality = "scottish"
})
2. Deserialize allows you to convert json format string to an object:
ScottishPerson = JsonSerializer.Deserialize<Person>(defaultPerson);
Product product = new Product();
product.ExpiryDate = new DateTime(2008, 12, 28);
JsonSerializer serializer = new JsonSerializer();
serializer.Converters.Add(new JavaScriptDateTimeConverter());
serializer.NullValueHandling = NullValueHandling.Ignore;
using (StreamWriter sw = new StreamWriter(@"c:json.txt"))
using (JsonWriter writer = new JsonTextWriter(sw))
{
serializer.Serialize(writer, product);
// {"ExpiryDate":new Date(1230375600000),"Price":0}
}