I am now able to deserialize a School from JSON, next step is to now insert the data into a Bar Chart using MVC.
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"}]}]
I have found out how to call the JSON file and view in the Console.WriteLine
.
var root = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<List<SchoolSubject>>(json)
foreach (var subject in root)
{
Console.WriteLine(subject.Subject);
foreach (var item in subject.AppScores)
{
Console.WriteLine("season: {0}, year: {1}", item.Season, item.year);
}
}
Calling from a Class:
public class SchoolSubjectAppScore
{
public string Season { get; set; }
public string year { get; set; }
}
public class SchoolSubject
{
public SchoolSubject() { this.AppScores = new List<SchoolSubjectAppScore>(); }
public string Subject { get; set; }
public List<SchoolSubjectAppScore> AppScores { get; set; }
}
Can anyone help to ammend this to use in MVC and call the variables from the JSON to a list to then display in a HTML webpage?
Thanks in advance.