I can strongly recommend using Newtonsoft.JSON for deserialization:
public static List<AveryLabelSheet> Load(string path = null)
{
if (path == null) path = GetSensiblePathToSheetDataFile();
if (!File.Exists(path)) throw new FileNotFoundException("Cannot locate the Sheet Data file:\n \"" + path + "\"\nPlease check the path and try again.");
try
{
all = JsonConvert.DeserializeObject<List<AveryLabelSheet>>(File.ReadAllText(path));
}
catch (Exception ex)
{
throw new FileLoadException("Unable to load Sheet Data.\nThe file \"" + path + "\" does not load correctly.", ex);
}
isLoaded = true;
return new List<AveryLabelSheet>(all);
}
One line of code does the whole job:
all = JsonConvert.DeserializeObject<List<AveryLabelSheet>>
You will need to install Newtonsoft.JSON: you can add it to your project via the NuGet Package Manager (Tools ... NuGet Package Manager ... Package Manager Console):
PM> Install-Package Newtonsoft.Json
As an aside, I'm using JSON data for the first time with a recent prioject, and it's remarkably easy with the Newtonsoft stuff: serialize and deserialize a whole list of a custom class in one line of code each! The only hassle I found was it only works if the relevant class properties have both public getter and setter - I originally used private setters, and the data failed to read back, understandably.