From Here you can deserialize an object from file in two way.
string json = File.ReadAllText(@"c:\myObj.json");
MyObject myObj = JsonConvert.DeserializeObject<MyObject>(json);
using (StreamReader file = File.OpenText(@"c:\myObj.json"))
{
JsonSerializer serializer = new JsonSerializer();
MyObject myObj2 = (MyObject)serializer.Deserialize(file, typeof(MyObject));
}
from here you can serialize an object to file in two way.
string json = JsonConvert.SerializeObject(myObj);
File.WriteAllText(@"c:\myObj.json", json);
using (StreamWriter file = File.CreateText(@"c:\myObj.json"))
{
JsonSerializer serializer = new JsonSerializer();
serializer.Serialize(file, myObj);
}
You can download Newtonsoft.Json from NuGet by following command
Install-Package Newtonsoft.Json