JSON File to View in MVC Bar Chart - C#

浪尽此生 提交于 2019-12-11 10:39:16

问题


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.

来源:https://stackoverflow.com/questions/34982984/json-file-to-view-in-mvc-bar-chart-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!