CSharp: amap's weather (json Deserialization of C# Objects)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | 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 ; } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | 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=
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!