private static List <WeatherObject> parceForecastWeatherJsonString(string jsonContentString) { List <WeatherObject> forecast = new List <WeatherObject>(); try { JObject obj = JObject.Parse(jsonContentString); JObject cityJson = (JObject)obj["city"]; CityObject city = parceCity(cityJson); JArray weatherList = (Newtonsoft.Json.Linq.JArray)obj["list"]; foreach (JObject weatherJson in weatherList) { WeatherObject weatherObj = parceWeather(city, weatherJson); weatherObj = parceForecastMainWeather(weatherObj, weatherJson); forecast.Add(weatherObj); } return(forecast); } catch (JsonReaderException e) { System.Diagnostics.Debug.WriteLine("-- Error parce json: {0} --", e.Message); } return(null); }
private static WeatherObject parceForecastMainWeather(WeatherObject weather, JObject obj) { var weatherJson = obj; WeatherMainInfo mainInfo = new WeatherMainInfo(); mainInfo.Pressure = (float)weatherJson["pressure"]; mainInfo.Humidity = (float)weatherJson["humidity"]; weatherJson = (JObject)obj["temp"]; mainInfo.Temp = (float)weatherJson["day"]; mainInfo.Temp_min = (float)weatherJson["min"]; mainInfo.Temp_max = (float)weatherJson["max"]; DayInfo dayInfo = new DayInfo(); dayInfo.Temp = (float)weatherJson["day"]; dayInfo.TempNight = (float)weatherJson["night"]; dayInfo.TempEve = (float)weatherJson["eve"]; dayInfo.TempMorn = (float)weatherJson["morn"]; weather.MainInfo = mainInfo; weather.DayInfo = dayInfo; return(parceWindWeather(weather, obj)); }
protected void weatherEventHandler(WeatherObject weatherObject, WebException webExeptin) { if (webExeptin == null) { if (weatherObject != null) { this.CurrentWeather = weatherObject; if (this.DidUpdateWeaherEventHandler != null) { this.DidUpdateWeaherEventHandler(this.CurrentWeather); } } else { System.Diagnostics.Debug.WriteLine("-- ERROR: weather object is nil --"); } } else { System.Diagnostics.Debug.WriteLine("-- ERROR: {0} --", webExeptin.Message); if (this.ErrorUpdateWeaherEventHandler != null) { this.ErrorUpdateWeaherEventHandler(webExeptin); } } }
private static WeatherObject parceWindWeather(WeatherObject weather, JObject obj) { Wind windInfo = new Wind(); windInfo.Speed = (float)obj["speed"]; windInfo.Deg = (float)obj["deg"]; weather.MainInfo.Wind = windInfo; return(weather); }
private static WeatherObject parceWeather(CityObject city, JObject obj) { WeatherObject weather = new WeatherObject(city); var weatherJson = obj["weather"][0]; weather.Id = (int)weatherJson["id"]; weather.Main = (string)weatherJson["main"]; weather.Description = (string)weatherJson["description"]; weather.Icon = (string)weatherJson["icon"]; return(weather); }
protected void DidUpdateWeaherEventHandler(WeatherObject weatherObj) { if (DidEndUpadateWeather != null) { DidEndUpadateWeather(); } float temperature = ConverterValueContext.convertTemperature(WeatherModel.CurrentWeather.MainInfo.Temp, this.TemperatureFormat); Temperature = string.Format("{0:0.#}", temperature); Main = WeatherModel.CurrentWeather.Main; WindSpeed = WeatherModel.CurrentWeather.MainInfo.Wind.Speed.ToString(); Humidity = WeatherModel.CurrentWeather.MainInfo.Humidity.ToString(); City = WeatherModel.CurrentWeather.City.Name; }
private static WeatherObject parceCurrentMainInfoWeather(WeatherObject weather, JObject obj) { var weatherJson = obj; WeatherMainInfo mainInfo = new WeatherMainInfo(); mainInfo.Temp = (float)weatherJson["temp"]; mainInfo.Pressure = (float)weatherJson["pressure"]; mainInfo.Humidity = (float)weatherJson["humidity"]; mainInfo.Temp_min = (float)weatherJson["temp_min"]; mainInfo.Temp_max = (float)weatherJson["temp_max"]; weather.MainInfo = mainInfo; return(weather); }
private static WeatherObject parceCurrentWeatherJsonString(string jsonContentString) { try { JObject obj = JObject.Parse(jsonContentString); CityObject city = parceCity(obj); WeatherObject weather = parceWeather(city, obj); weather = parceCurrentMainInfoWeather(weather, (JObject)obj["main"]); weather = parceWindWeather(weather, (JObject)obj["wind"]); return(weather); } catch (JsonReaderException e) { System.Diagnostics.Debug.WriteLine("-- Error parce json: {0} --", e.Message); } return(null); }
public WatherCurrentModel(CityObject city) : base() { CurrentWeather = new WeatherObject(city); }