예제 #1
0
        protected void GetWeatherInfo(object sender, EventArgs e)
        {
            string appId = "447a766794a63a639f84510f0acdf231";
            string url   = string.Format("http://api.openweathermap.org/data/2.5/forecast/daily?q={0}&units=metric&cnt=1&APPID={1}", txtCity.Text.Trim(), appId);

            using (WebClient client = new WebClient())
            {
                string json = client.DownloadString(url);

                WeatherInfo weatherInfo = (new JavaScriptSerializer()).Deserialize <WeatherInfo>(json);
                lblCity_Country.Text    = weatherInfo.city.name + "," + weatherInfo.city.country;
                imgCountryFlag.ImageUrl = string.Format("http://openweathermap.org/images/flags/{0}.png", weatherInfo.city.country.ToLower());
                lblDescription.Text     = weatherInfo.list[0].weather[0].description;
                imgWeatherIcon.ImageUrl = string.Format("http://openweathermap.org/img/w/{0}.png", weatherInfo.list[0].weather[0].icon);
                lblTempMin.Text         = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.min, 1));
                lblTempMax.Text         = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.max, 1));
                lblTempDay.Text         = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.day, 1));
                lblTempNight.Text       = string.Format("{0}°С", Math.Round(weatherInfo.list[0].temp.night, 1));
                lblHumidity.Text        = weatherInfo.list[0].humidity.ToString();
                tblWeather.Visible      = true;
            }
        }
예제 #2
0
        static void Main(string[] args)
        {
            string appkey = "43010404ec713e82555f7baa4deb50ca";

            string url1 = "http://v.juhe.cn/weather/index";

            var parameters1 = new Dictionary <string, string>();

            //string city1 = Encoding.UTF8.GetString(Encoding.UTF8.GetBytes("北京"));
            parameters1.Add("cityname", "北京");
            parameters1.Add("dtype", "");
            parameters1.Add("format", "");
            parameters1.Add("key", appkey);
            string result1 = sendPost(url1, parameters1, "GET");

            string aaa = "{\"employees\": [{\"firstName\": \"John\",\"lastName\": \"Doe\"},{\"firstName\": \"Anna\",\"lastName\": \"Smith\"},{\"firstName\": \"Peter\",\"lastName\": \"Jones\"}]}";



            DataTable dt = new DataTable();

            dt = Comm.Json.JsonToDataTable(aaa, "employees");

            //JsonObject newObj1 = new JsonObject(result1);
            JsonSerializer serializer = new JsonSerializer();
            StringReader   sr         = new StringReader(result1);
            object         o          = serializer.Deserialize(new JsonTextReader(sr), typeof(WeatherInfo));
            WeatherInfo    info       = o as WeatherInfo;
            var            resultcode = info.resultcode;
            var            reason     = info.reason;
            Result         result     = info.result;
            SK             skInfo     = result.sk;
            int            temp       = skInfo.temp;
            string         s1         = skInfo.wind_direction;
            string         s2         = skInfo.wind_strength;
            string         s3         = skInfo.humidity;
            string         s4         = skInfo.time;
        }
예제 #3
0
 public Client()
 {
     _weatherInfo = new WeatherInfo();
 }