Example #1
0
 public void weatherinit(weatherinfo info)
 {
     try
     {
         this.txttime.Text = info.ptime;
         this.txtweather.Text = info.weather;
         this.txtcityname.Text = info.city;
         this.temp1.Text = info.temp1;
         this.temp2.Text = info.temp2;
         string d = Convert.ToInt32(info.img1.Split('.')[0].Replace("d", "")).ToString("00");
         string n = Convert.ToInt32(info.img2.Split('.')[0].Replace("n", "")).ToString("00");
         this.imgday.Image = Image.FromFile(Path.Combine(System.IO.Directory.GetCurrentDirectory(), "weather\\" + d + ".png"));
         this.imgnight.Image = Image.FromFile(Path.Combine(System.IO.Directory.GetCurrentDirectory(), "weather\\" + n + "_.png"));
     }
     catch
     {
         txtcityname.Text = "数据获取异常";
     }
 }
Example #2
0
        private weatherinfo GetWeatherByCityID(string cityid)
        {
            string url = String.Format("http://www.weather.com.cn/data/cityinfo/{0}.html", cityid);
            CredentialCache cache = new CredentialCache();
            string jsonstring = Router.SendRequest(url, Encoding.UTF8, cache);

            //weatherinfo Info = (weatherinfo)JsonConvert.DeserializeObject(jsonstring);
            JObject weather = JsonConvert.DeserializeObject(jsonstring) as JObject;
            weatherinfo info = new weatherinfo();

            info.city = weather["weatherinfo"]["city"].ToString();
            info.cityid = weather["weatherinfo"]["cityid"].ToString();
            info.temp1 = weather["weatherinfo"]["temp1"].ToString();
            info.temp2 = weather["weatherinfo"]["temp2"].ToString();
            info.weather = weather["weatherinfo"]["weather"].ToString();
            info.img1 = weather["weatherinfo"]["img1"].ToString();
            info.img2 = weather["weatherinfo"]["img2"].ToString();
            try
            {
                info.ptime = weather["weatherinfo"]["ptime"].ToString();
            }
            catch
            {
                info.ptime = "11:00";
            }
            //return Router.getProperties<weatherinfo>(info).Replace(",", "\r\n");
            return info;
        }