using System.Collections.Generic;
using Newtonsoft.Json.Linq;
public static void Main()
""recordType"": ""working"",
""workTimeStart"": ""08:00"",
""workTimeEnd"": ""22:00""
""recordType"": ""working"",
""workTimeStart"": ""08:00"",
""workTimeEnd"": ""22:00""
""recordType"": ""working"",
""workTimeStart"": ""08:00"",
""workTimeEnd"": ""22:00""
""recordType"": ""working"",
""workTimeStart"": ""08:00"",
""workTimeEnd"": ""22:00""
""recordType"": ""working"",
""workTimeStart"": ""08:00"",
""workTimeEnd"": ""22:00""
""recordType"": ""working"",
""workTimeStart"": ""08:00"",
""workTimeEnd"": ""22:00""
""recordType"": ""working"",
""workTimeStart"": ""08:00"",
""workTimeEnd"": ""22:00""
""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""
var dto = JsonConvert.DeserializeObject<AppraiserCalendarDto>(content);
Console.WriteLine("Records:");
foreach (var kvp in dto.Records)
Console.WriteLine(string.Format(" {0} {1} {2:hh':'mm} - {3:hh':'mm}", kvp.Key.ToShortDateString(), kvp.Value.RecordType, kvp.Value.WorkTimeStart, kvp.Value.WorkTimeEnd));
Console.WriteLine("Links:");
foreach (var link in dto.Links)
Console.WriteLine(string.Format(" {0}: {1}", link.Rel, link.Href));
[JsonConverter(typeof(AppraiserCalendarDtoConverter))]
public class AppraiserCalendarDto
public Dictionary<DateTime, Record> Records { get; set; }
[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 string Rel { get; set; }
public string Href { get; set; }
class AppraiserCalendarDtoConverter : JsonConverter
public override bool CanConvert(Type objectType)
return (objectType == typeof(AppraiserCalendarDto));
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
JObject jo = JObject.Load(reader);
var dto = new AppraiserCalendarDto();
dto.Links = jo["links"].ToObject<List<AppraiserCalendarDto.Link>>();
var dict = new Dictionary<DateTime, AppraiserCalendarDto.Record>();
foreach (JProperty prop in jo.Properties().Where(p => p.Name != "links"))
var date = DateTime.Parse(prop.Name);
var record = prop.Value["regular"].ToObject<AppraiserCalendarDto.Record>();
public override bool CanWrite
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
throw new NotImplementedException();