Exemplo n.º 1
0
        public WeatherInfo.RootObject getWeather(string city_name)
        {
            string    key  = "sua key";
            string    url  = string.Format("https://api.hgbrasil.com/weather?key={0}&city_name={1}&format=json", key, city_name);
            WebClient web  = new WebClient();
            var       json = web.DownloadString(url);

            byte[] bytes = Encoding.Default.GetBytes(json);
            json = Encoding.UTF8.GetString(bytes);
            var result = JsonConvert.DeserializeObject <WeatherInfo.RootObject>(json);

            WeatherInfo.RootObject outPut = result;

            return(result);
        }
Exemplo n.º 2
0
        bool exceptionPrevisaoTempo = false; //Caso de algum erro com webservice previsao do tempo
        public Form1()
        {
            InitializeComponent();
            dateTimePicker1.Value = DateTime.Now;
            RetornaDados();
            timer1.Start();

            Rectangle workingArea = Screen.GetWorkingArea(this);

            this.Location = new Point(workingArea.Right - Size.Width, workingArea.Bottom - Size.Height);

            PrevisaoTempo previsaoTempo = new PrevisaoTempo();

            try
            {
                result = previsaoTempo.getWeather(cidade);
            }
            catch (Exception)
            {
                exceptionPrevisaoTempo = true;
            }
        }