I'm able to write to a text file a list of objects with the JSON serializer, however my aim is to populate a list on demand from the json text file. I'm a little puzzled as how to do this. I'm not experienced with JSON at all and have only been playing around with it today for the first time.
Here is the code I use to write my list of ints to the JSON.
class LockTime
{
public int Start { get; set; }
public int End {get; set; }
public LockTime (int start, int end)
{
Start = start;
End = end;
}
}
This is the class where I'm writing to the JSON file (or the part where I'm doing it)
private List<LockTime> times;
int timeStart = pickerTimeStart.Value.Hour + pickerTimeStart.Value.Minute;
int timeEnd = pickerTimeEnd.Value.Hour + pickerTimeEnd.Value.Minute;
LockTime bla = new LockTime(timeStart, timeEnd);
times.Add(theTime);
string meh = JsonConvert.SerializeObject(times, Formatting.Indented);
File.WriteAllText(@filePath, meh);
There are 2 things I want to be able to do. The first is to populate a listview from the json file. In pseudo code
Deserialize the file with something like times = JsonConvert.DeserializeObject>(json);
but I can't quite wrap my head around how to go from the text file straight to the array and then how to display it in the listview. Before I was working with JSON I was working with a straight forward text file where I was firstly drawing a bunch of ints row by row and then displaying them in the listview via lstTime.Items.AddRange(GetTimes().Select(t => new ListViewItem(t)).ToArray());
Any idea how?