I'm trying to deserialize a School to then insert into a Bar Chart Later. The JSON object looks like:
[{"Subject": "TEST APP","AppScores": [{"Season": "AAAAAAAAAAAAAAAAAAAA","year": "1"}, {"Season": "BBBBBBBBBBBBBBBBBBBBB","year": "2"}]}, {"Subject": "TEST APP2","AppScores": [{"Season": "CCCCCCCCCCC","year": "3"}, {"Season": "DDDDDDDDDDDDDDDDD","year": "4"}]}]
The output I am hoping to see in the Console.WriteLine();
Subject: TEST APP
AppScores
Season: AAAAAAAAAAAAAAAAAAAA
Year: 1
Season: BBBBBBBBBBBBBBBBBBBBB
Year: 2
Subject: TESTAPP2
AppScores
Season: CCCCCCCCCCC
Year: 3
Season: DDDDDDDDDDDDDDDDD
Year: 4
I have seen this been done in multiple of ways using similar code below.
School subject = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<School>(json);
foreach (var item in subject.data)
{Console.WriteLine("season: {0}, year: {1}", item.season, item.year); Console.ReadLine();}
Calling from a Class:
public class School
{
public List<SchoolSubjects> data { get; set; }
}
public class SchoolSubjects
{
public string year { get; set; }
public string season { get; set; }
}
Can anyone help to amend this code as I cant find any examples that would do this? Thanks in advance.