public static async Task <List <CountyInfo> > GetCountyInfo() { var countyResponse = await client.GetAsync("http://api.scb.se/OV0104/v1/doris/sv/ssd/START/ME/ME0104/ME0104D/ME0104T4"); var countyInfo = new List <CountyInfo>(); string countyResponseBody = countyResponse.Content.ReadAsStringAsync().Result; CountyData countyData = JsonConvert.DeserializeObject <CountyData>(countyResponseBody); foreach (var item in countyData.Variables) { if (item.Code == "Region") { for (int i = 0; i < item.Values.Count; i++) { var county = new CountyInfo(); county.Id = item.Values[i]; county.Name = item.ValueTexts[i]; countyInfo.Add(county); } } } return(countyInfo); }
/// <summary> /// Checks whether the given county data is a valid model, and then proceeds to look through any connected models /// that are not in the checkedModels set and ensure that they all result in a valid model. /// </summary> /// <param name="countyData">The model to check.</param> /// <param name="checkedModels">A set of models that have already been checked.</param> public static void ValidateCountyData(CountyData countyData, HashSet <int> checkedModels) { if (countyData == null) { throw new ArgumentException("CountyData cannot be null."); } if (countyData.Year == -1) { throw new ArgumentException("CountyData.Year cannot be the default value."); } if (countyData.Population == -1) { throw new ArgumentException("CountyData.Population cannot be the default value."); } if (double.IsNaN(countyData.Areal)) { throw new ArgumentException("CountyData.Areal cannot be null."); } checkedModels.Add(countyData.GetHashCode()); }