internal Weather(string zipCode, WeatherInformation[] forecast) { _zipCode = zipCode; _forecast = forecast; _timeStamp = " "; _description = " "; _location = " "; _temperature = " "; }
private static Weather ParseWeather(string zipCode, string json) { JsonValue jsonObject = JsonValue.Parse(json); JsonValue location = jsonObject["value"]["items"][0]["loc"]; JsonValue currentConditions = jsonObject["value"]["items"][0]["cc"]; JsonValue forecastConditions = jsonObject["value"]["items"][0]["dayf"]["day"]; WeatherInformation[] forecastItems = new WeatherInformation[4]; Weather weather = new Weather(zipCode, forecastItems); weather.Location = location["dnam"]; weather.TimeStamp = currentConditions["lsup"]; weather.Description = currentConditions["t"]; weather.Temperature = currentConditions["tmp"]; weather.ImageUri = "/Images/" + currentConditions["icon"] + ".png"; for (int i = 1; i < 5; i++) { WeatherInformation wi = new WeatherInformation(); JsonValue forecast = forecastConditions[i]; JsonValue dayInfo = forecast["part"][0]; JsonValue nightInfo = forecast["part"][1]; wi.Day = forecast["t"].ToString().Substring(1, 3); wi.Date = forecast["dt"]; wi.Low = forecast["low"]; wi.High = forecast["hi"]; wi.DayDescription = dayInfo["t"]; wi.DayImageUrl = "/Images/" + dayInfo["icon"] + ".png"; wi.NightDescription = nightInfo["t"]; wi.NightImageUrl = "/Images/" + nightInfo["icon"] + ".png"; forecastItems[i - 1] = wi; } return(weather); }
private static Weather ParseWeather(string zipCode, string json) { JsonValue jsonObject = JsonValue.Parse(json); JsonValue location = jsonObject["value"]["items"][0]["loc"]; JsonValue currentConditions = jsonObject["value"]["items"][0]["cc"]; JsonValue forecastConditions = jsonObject["value"]["items"][0]["dayf"]["day"]; WeatherInformation[] forecastItems = new WeatherInformation[4]; Weather weather = new Weather(zipCode, forecastItems); weather.Location = location["dnam"]; weather.TimeStamp = currentConditions["lsup"]; weather.Description = currentConditions["t"]; weather.Temperature = currentConditions["tmp"]; weather.ImageUri = "/Images/" + currentConditions["icon"] + ".png"; for (int i = 1; i < 5; i++) { WeatherInformation wi = new WeatherInformation(); JsonValue forecast = forecastConditions[i]; JsonValue dayInfo = forecast["part"][0]; JsonValue nightInfo = forecast["part"][1]; wi.Day = forecast["t"].ToString().Substring(1, 3); wi.Date = forecast["dt"]; wi.Low = forecast["low"]; wi.High = forecast["hi"]; wi.DayDescription = dayInfo["t"]; wi.DayImageUrl = "/Images/" + dayInfo["icon"] + ".png"; wi.NightDescription = nightInfo["t"]; wi.NightImageUrl = "/Images/" + nightInfo["icon"] + ".png"; forecastItems[i - 1] = wi; } return weather; }