次の JSON が menu.json ファイルに保存されています。
{
"menu": {
"menuitems": [
{
"label": "Account",
"listview": "Account List"
},
{
"label": "Documents",
"listview": "Document List"
}
]
}
}
このデータを手動でファイルに書き込みました。次の関数を使用してこのデータを取得します。
public ActionResult GetFromFile(string path)// path points to the menu.json file
{
StreamReader sr = new StreamReader(path);
string filedata = sr.ReadToEnd();
Menu menu = JsonSerializer.DeserializeToString<Menu>(filedata);
return Json(menu, JsonRequestBehavior.Allowget);
}
menu として応答を取得すると、クラス フィールドで区切られません。さらに、私は単一のクラスを持っているので、jsonファイルデータをこのクラスに保存するにはどうすればよいですか?? クラス構造に変更はありますか? 私のメニュークラスは次のとおりです。
public class Menu
{
public string Label {get;set;}
public string Listview {get;set;}
}