private void RefreshWeather()
{
try
{
string url = "http://m.weather.com.cn/data/" + string_CityCode + ".html";
Encoding encoding = Encoding.UTF8;
GetWebContent gwc = new GetWebContent();
string result = gwc.GetWebContentByUrl(url, encoding);
if (result.Contains("链接超时") || result.Contains("链接异常")) return;
result = GetJsonContent(result);
if (string.IsNullOrEmpty(result)) return;
WeatherInfo wi = JSON.Json2Object<WeatherInfo>(result);
weatherCity.Text = wi.city;//城市
weatherDate.Text = wi.date_y;//日期
weatherWeek.Text = wi.week;//星期
weatherTemp.Text = "温度 " + wi.temp1;//温度
weatherHumidity.Text = "";//湿度
weatherWeather.Text = wi.weather1;//天气
weatherWind.Text = wi.wind1;//风向
if (File.Exists(Application.StartupPath + @"\Image\" + wi.img1 + ".png"))
{
weatherImg.Image = Image.FromFile(Application.StartupPath + @"\Image\" + wi.img1 + ".png");
}
weatherComplex.Text = "紫外线:" + wi.index_uv + "\r\n" +
"洗车:" + wi.index_xc + "\r\n" +
"旅游:" + wi.index_tr + "\r\n" +
"舒适指数:" + wi.index_co + "\r\n" +
"晨练:" + wi.index_cl + "\r\n" +
"晾晒:" + wi.index_ls + "\r\n" +
"过敏:" + wi.index_ag + "\r\n" +
"今日穿衣指数:" + wi.index_d;
weatherTime.Text = "更新时间:" + DateTime.Now.ToString("HH:mm:ss");
}
catch (Exception ex)
{
log.WriteLog(ex.ToString());
}
}