【发布时间】:2017-05-19 14:38:04
【问题描述】:
我正在使用 NewtonSoft 的 JsonConvert.DeserializeObject<AppraiserCalendarDto>(content) 方法并尝试反序列化以下内容以了解资源是否在特定日期工作:
{
"2017-05-18": {
"regular": {
"recordType": "working",
"workTimeStart": "08:00",
"workTimeEnd": "22:00"
}
},
"2017-05-19": {
"regular": {
"recordType": "working",
"workTimeStart": "08:00",
"workTimeEnd": "22:00"
}
},
"2017-05-22": {
"regular": {
"recordType": "working",
"workTimeStart": "08:00",
"workTimeEnd": "22:00"
}
},
"2017-05-23": {
"regular": {
"recordType": "working",
"workTimeStart": "08:00",
"workTimeEnd": "22:00"
}
},
"2017-05-24": {
"regular": {
"recordType": "working",
"workTimeStart": "08:00",
"workTimeEnd": "22:00"
}
},
"2017-05-25": {
"regular": {
"recordType": "working",
"workTimeStart": "08:00",
"workTimeEnd": "22:00"
}
},
"2017-05-26": {
"regular": {
"recordType": "working",
"workTimeStart": "08:00",
"workTimeEnd": "22:00"
}
},
"links": [
{
"rel": "canonical",
"href": "https://api.somedomain.com/rest/core/v1/resources/workSchedules/calendarView?dateFrom=2017-05-18&dateTo=2017-05-28"
},
{
"rel": "describedby",
"href": "https://api.somedomain.com/rest/core/v1/metadata-catalog/resources"
}
]
}
我要填充的模型类如下:
public class AppraiserCalendarDto
{
public Dictionary<DateTime, Record> Records { get; set; }
public class Record
{
[JsonProperty("recordType")]
public string RecordType { get; set; }
[JsonProperty("workTimeStart")]
public TimeSpan WorkTimeStart { get; set; }
[JsonProperty("workTimeEnd")]
public TimeSpan WorkTimeEnd { get; set; }
}
public List<Link> Links { get; set; }
public class Link
{
[JsonProperty("rel")]
public string Rel { get; set; }
[JsonProperty("href")]
public string Href { get; set; }
}
}
不幸的是,只有List<Link> Links 被填充,而Records 字典为空。
我尝试使用Dictionary<string, Record> 而不是Dictionary<DateTime, Record>,结果相同。
非常感谢任何反馈。
【问题讨论】:
标签: c# json json.net deserialization json-deserialization