I'm trying to parse data from a .json file, and put them in a list of a class called "Track"
The class looks like this:
public class Track
{
public string Artist { get; set; }
public string Album { get; set; }
public string Title { get; set; }
public int TrackNumber { get; set; }
public string Filepath { get; set; }
public int SongLength { get; set; }
public Color RGB { get; set; }
}
And my code looks like this:
private void Load()
{
using (StreamReader r = new StreamReader("C:\Users\Swagger\Desktop\Test\MusicCacheP.json"))
{
string json = r.ReadToEnd();
List<Track> items = JsonConvert.DeserializeObject<List<Track>>(json);
MSG(items.Count.ToString());
//MSG is just a function which gives me a messagebox. I'm too lazy to write the full messagebox.show.. ;)
}
}
And I don't know if this matters but here's some of the json code:
{"Artist":"Dirty South","Album":"Until the End","Title":"Until the End (Michael Brun Mix) [feat. Joe Gil]","TrackNumber":0,"Filepath":"\\\\DAVIDIOSO\\Users\\hasht_000\\Music\\Dirty South - Until the End (Michael Brun Mix) [feat. Joe Gil].mp3","SongLength":21,"RGB":""}
I haven't really used Json that much to know fully how it works. I'm the kind of person who likes to learn by doing. But if you have some good pages to read about json in C#, I'd be glad to read it :)
EDIT:
I'm going crazy! I can't figure out why I'm getting this exception..
I'm only getting exceptions for the file paths.
And the crazy thing is that I have another file with all the filepaths inside of it, which I also read with json. And that's working out great.
A "ghetto" solution would be to read that file which only contains filepaths and use that to fill my list of Track? But it would be nice to get this sorted out.. Any help is really appreciated! :)