【发布时间】:2019-10-12 01:20:14
【问题描述】:
我想用 C# 代码编写一个 json 文件,如下 json 文件所示:
{
"Monday": [
{
"class": "Example",
"time": "09:00"
},
{
"class": "Example2",
"time": "09:50"
}
],
"Tuesday": [
{
"class": "Example3",
"time": "09:00"
},
{
"class": "Example4",
"time": "09:50"
}
]
}
编辑这是我正在使用的类:
public class Lesson {
public string title { get; set; }
public string timeStart { get; set; }
public string timeEnd { get; set; }
}
我找到了将单个对象写入文件的方法,尽管我没有找到关于数组的任何内容。
如果解决方案很明显,我在浪费您的时间,请提前原谅,但我最近才开始使用 json 文件。
提前致谢,
苯乙炔
【问题讨论】:
-
您可以使用
Dictionary<string, List<Dictionary<string, string>>>或在此处粘贴您的 JSON:QuickType 并使用提供的类模型来序列化/反序列化 JSON。 -
使用
Json.NET库,它有你需要的一切。 -
您的课程根本没有映射到您的 json。要获得有用的答案,您必须提供更多信息。