CSharp: amap's weather (json Deserialization of C# Objects)
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Model { /// <summary> /// 高德天气 /// </summary> public class AMapWeatherInfo { public string status { get; set; } public string count { get; set; } public string info { get; set; } public string infocode { get; set; } public List<Life> lives { get; set; } } /// <summary> /// /// </summary> public class Life { public string province { get; set; } public string city { get; set; } public string adcode { get; set; } public string weather { get; set; } public string temperature { get; set; } public string winddirection { get; set; } public string windpower { get; set; } public string humidity { get; set; } public string reporttime { get; set; } public string temperature_float { get; set; } public string humidity_float { get; set; } } }
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.IO; using System.Text; using System.Web.Script.Serialization; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Model; namespace WebAppPdfDemo { /// <summary> /// https://lbs.amap.com/api/webservice/guide/api/weatherinfo/#t1 /// </summary> public partial class AMapWetherDemo : System.Web.UI.Page { /// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string requestUrl = string.Format("https://restapi.amap.com/v3/weather/weatherInfo?key={0}&city={1}", "geovindu", "110101"); //Uri myUri = new Uri(requestUrl); //// Create a new request to the above mentioned URL. //WebRequest myWebRequest = WebRequest.Create(myUri); //// Assign the response object of 'WebRequest' to a 'WebResponse' variable. //WebResponse myWebResponse = myWebRequest.GetResponse(); //string response = string.Empty; //using (StreamReader reader = new StreamReader(myWebResponse.GetResponseStream(), Encoding.UTF8)) //Encoding.UTF8 //{ // response = reader.ReadToEnd(); //} WebClient client = new WebClient(); client.Encoding = Encoding.UTF8; string str = client.DownloadString(requestUrl); AMapWeatherInfo info = new AMapWeatherInfo(); JavaScriptSerializer j = new JavaScriptSerializer(); if (!string.IsNullOrEmpty(str)) { info = j.Deserialize<AMapWeatherInfo>(str); } Response.Write(info.lives[0].city); Response.Write(info.lives[0].weather); Response.Write(info.lives[0].humidity); Response.Write(info.lives[0].temperature); Response.Write(info.lives[0].reporttime); Response.Write("<br/>"); AMapWeatherInfo dd = GetWeather("110101", "geovindu"); Response.Write(str+"<br/>"); Response.Write(dd.lives[0].reporttime); } } /// <summary> /// /// </summary> /// <param name="city"></param> /// <param name="key"></param> /// <param name="re"></param> /// <returns></returns> public static AMapWeatherInfo GetWeather(string city, string key) { AMapWeatherInfo info = null; try { WebClient client = new WebClient(); client.Encoding = Encoding.UTF8; string url = String.Format("https://restapi.amap.com/v3/weather/weatherInfo?key={0}&city={1}", key, city); //将返回的json数据转为JSON对象 string str=client.DownloadString(url); if (!string.IsNullOrWhiteSpace(str)) { info = new AMapWeatherInfo(); info = JsonConvert.DeserializeObject<AMapWeatherInfo>(str); } } catch(Exception ex) { ex.Message.ToString(); } return info; } } }
https://github.com/public-apis/public-apis
天气相关API接口
和风天气
https://console.qweather.com/#/apps
https://github.com/qwd/LocationList
https://api.qweather.com/v7/weather/3d?location=101010100&key= 收费
https://devapi.qweather.com/v7/weather/3d?location=101010100&key= 免费
https://devapi.qweather.com/v7/weather/now?location=101010100&key=
实时天气:https://devapi.qweather.com/v7/weather/now?key=【你的 API KEY】&
逐小时天气预报:https://devapi.qweather.com/v7/weather/24h?key=【你的 API KEY】&
7日逐天天气预报:https://devapi.qweather.com/v7/weather/7d?key=【你的 API KEY】&
实时空气质量:https://devapi.qweather.com/v7/air/now?key=【你的 API KEY】&
https://restapi.amap.com/v3/weather/weatherInfo?key=110101&city=1010101&extensions=all
https://lbs.amap.com/api/webservice/guide/api/weatherinfo
https://restapi.amap.com/v3/weather/weatherInfo?city=110101&key=
https://restapi.amap.com/v3/weather/weatherInfo?city=110101&key=
https://free-api.heweather.net/s6/weather/now?location=101010100&key=
https://dev.qweather.com/showcase/
https://github.com/InTereSTingHE/QWeatherAPI-Python
https://api.openweathermap.org/data/2.5/weather?q=London,uk&APPID=
https://api.openweathermap.org/data/2.5/weather?q=shenzhen,cn&APPID=
https://home.openweathermap.org/api_keys
https://api.openweathermap.org/data/2.5/weather?lat=44.34&lon=10.99&appid=
https://api.openweathermap.org/data/2.5/weather?lat=44.34&lon=10.99&appid=
http://api.openweathermap.org/data/2.5/weather?q=shenzhen,cn&APPID=
http://api.openweathermap.org/data/2.5/weather?q=shenzhen,cn&APPID=