I have working method for saving data into JSON file. Now i need to read that file and display in console.
What i'm missing?
Below is my code
My method for reading:
public static void Read(string path, Workspace workspace)
{
using (StreamReader file = new StreamReader(path))
{
try
{
string json = file.ReadToEnd();
var serializerSettings = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
var workspace1 = JsonConvert.DeserializeObject<Workspace>(json, serializerSettings);
workspace = workspace1;
}
catch (Exception)
{
Console.WriteLine("Problem reading file");
}
}
}
In program.cs
Serializer.Save("C:\Users\user\Desktop\test.json", workspace);
Serializer.Read("C:\Users\user\Desktop\test.json", workspace);
Console.ReadKey();
On the left is my json file and on the right is what i would like to show in the console.
See Question&Answers more detail:os