我在 menu.json 文件中保存了以下 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;}
}