[英]How to use newtonsoft.Json to serialize and deserialize multiple objects into and out of a list
[英]How do I deserialize list of complex objects with newtonsoft.json
我需要使用Newtonsoft.json反序列化此JSON:
{
"Monday": [
{
"begin": "08:00:00",
"end": "17:00:00",
"duration": "09:00:00"
}
],
"Tuesday": [
{
"begin": "08:00:00",
"end": "17:00:00",
"duration": "09:00:00"
}
]
}
定义一个类Times
public class Times { public string Begin { get; set; } public string End { get; set; } public string Duration { get; set; } }
将JSON反序列化为Dictionary<string, List<Times>>
。 字典的键将是日期名称,例如Monday
, Tuesday
等。
var dict = JsonConvert.DeserializeObject<Dictionary<string, List<Times>>>(jsonString);
小提琴: https : //dotnetfiddle.net/CRbTZn
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.