private List<DTO.MarketDay> Parse(string responseContent) { var days = new List<DTO.MarketDay>(); JObject json = JObject.Parse(responseContent); JToken outer = json["calendar"]["days"].FirstOrDefault(); if (outer != null) { JArray array = null; if (((JProperty)outer).Value is JArray) array = (JArray)((JProperty)outer).Value; else throw new ArgumentOutOfRangeException("Expected array not found at json[\"calendar\"][\"days\"].Children()"); for (int i = 0; i < array.Count; i++) { var day = new DTO.MarketDay(); foreach (JToken token in array[i].Children()) { var property = (JProperty)token; switch (property.Name) { case "date": day.Date = DateTime.Parse((string)property.Value); break; case "status": if (String.Compare((string)property.Value, "open", true) == 0) day.IsOpen = true; break; case "description": day.Description = (string)property.Value; break; case "premarket": day.PreMarket = ParseInterval(token); break; case "open": day.Open = ParseInterval(token); break; case "postmarket": day.PostMarket = ParseInterval(token); break; } } days.Add(day); } } else throw new NullReferenceException("No child found at json[\"calendar\"][\"days\"]"); return days; }
private List <DTO.MarketDay> Parse(string responseContent) { var days = new List <DTO.MarketDay>(); JObject json = JObject.Parse(responseContent); JToken outer = json["calendar"]["days"].FirstOrDefault(); if (outer != null) { JArray array = null; if (((JProperty)outer).Value is JArray) { array = (JArray)((JProperty)outer).Value; } else { throw new ArgumentOutOfRangeException("Expected array not found at json[\"calendar\"][\"days\"].Children()"); } for (int i = 0; i < array.Count; i++) { var day = new DTO.MarketDay(); foreach (JToken token in array[i].Children()) { var property = (JProperty)token; switch (property.Name) { case "date": day.Date = DateTime.Parse((string)property.Value); break; case "status": if (String.Compare((string)property.Value, "open", true) == 0) { day.IsOpen = true; } break; case "description": day.Description = (string)property.Value; break; case "premarket": day.PreMarket = ParseInterval(token); break; case "open": day.Open = ParseInterval(token); break; case "postmarket": day.PostMarket = ParseInterval(token); break; } } days.Add(day); } } else { throw new NullReferenceException("No child found at json[\"calendar\"][\"days\"]"); } return(days); }