首页 > 其他分享 >CSharp: weather

CSharp: weather

时间:2023-12-11 18:44:38浏览次数:23  
标签:string weather https CSharp using com public

 

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=

 

标签:string,weather,https,CSharp,using,com,public
From: https://www.cnblogs.com/geovindu/p/17895123.html

相关文章

  • CSharp: vs 2022
    package.json {"name":"healthcheck","version":"0.0.0","scripts":{"ng":"ng","start":"echoStarting...&&ngserve","build&......
  • 在Winform中通过LibVLCSharp回调函数获取视频帧
    参考资料:VlcVideoSourceProvider优点:实现视频流的动态处理。缺点:视频解码(CPU/GPU)后图像处理CPU占用率高。在Winform中通过LibVLCSharp组件获取视频流中的每一帧图像,需要设置回调函数,主要是SetVideoFormatCallbacks和SetVideoCallbacks,其定义如下所示:///<summary>///Setde......
  • 华为最高学术成果发表 —— 《Nature》正刊发表论文《Accurate medium-range global w
          论文《Accuratemedium-rangeglobalweatherforecastingwith3Dneuralnetworks》的《Nature》地址:https://www.nature.com/articles/s41586-023-06185-3.pdf   论文的代码地址:https://github.com/198808xc/Pangu-Weather   这篇论文可以......
  • csharp基础
    学习/csharp学习/csharpDay1;Day2:1.Solution:FirstProject2.Project:FirstProject3.C#file:FirstProject4.Class:FirstProject5.Classmember:a.Method:MyMethodb.LocalVariable:myVariablec.Globalvariable:MyVariableCommonmath:pow,abs......
  • CSharp: Sorting Algorithms
     /*****************************************************************//***\fileSortingAlgorithm.cs*\briefcsharpSortingAlgorithms算法*IDEvs2022C#.net6.0*\authorgeovindu*\dateSeptember282023**************************......
  • CSharp_exe执行文件点击运行无反应;
    问题:点击试图运行exe可执行文件,但无法运行!解决思路:首先,想到的就是C#项目出错;再者就是运行环境缺少支持,查看Microsoft.NETFramework2.0以及Microsoft.NETFramework3.5是否安装,没安装的应该就不能运行的,所以装上即可!......
  • CSharp在Linux上使用Tesseract-OCR
    CSharp在Linux上使用Tesseract-OCR 1主要思路在Linux环境中使用ASP.NETCore调用TesseractOCR引擎可以按照以下步骤进行操作: 1确保你已经在Linux上安装和配置了TesseractOCR引擎。2在你的ASP.NETCore项目中,使用NuGet包管理器或dotnet命令行工具将Tesseract包添加......
  • csharp实现大文件上传
    ​ IE的自带下载功能中没有断点续传功能,要实现断点续传功能,需要用到HTTP协议中鲜为人知的几个响应头和请求头。 一. 两个必要响应头Accept-Ranges、ETag        客户端每次提交下载请求时,服务端都要添加这两个响应头,以保证客户端和服务端将此下载识别为可以断点续......
  • csharp实现文件夹的上传和下载
    ​ javaweb上传文件上传文件的jsp中的部分上传文件同样可以使用form表单向后端发请求,也可以使用ajax向后端发请求    1.通过form表单向后端发送请求         <formid="postForm"action="${pageContext.request.contextPath}/UploadServlet"method="post"e......
  • csharp上传文件到服务器指定文件夹问题
    ​ 以ASP.NETCoreWebAPI 作后端 API ,用 Vue 构建前端页面,用 Axios 从前端访问后端 API,包括文件的上传和下载。 准备文件上传的API #region 文件上传  可以带参数        [HttpPost("upload")]        publicJsonResultuploadProject(I......