在Visual Basic中使用JSON文件从API获取天气信息 [英] Using a JSON file in Visual Basic to Get Weather Information from an API

查看:128
本文介绍了在Visual Basic中使用JSON文件从API获取天气信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


获取和显示JSON文件值的最佳方法是什么。我想读的文件可以在以下网址找到:


https://api.weather.gov/zones/forecast/KSZ015/forecast


https://api.weather.gov/stations/KICT/observations/latest


在KSZ015和KICT中,它们将替换为{TextBox3.Text},以便用户可以输入他们所在位置的信息。


我尝试使用NWS提供的方法将它们转换为XML文件,但他们不提供XML格式的这两个功能,只提供JSON。我可以用XML成功完成天气预警。


如何从JSON提要中获取信息并显示每条信息(温度,文字描述,露点,湿度)等等和特定日期或天数的预测?


谢谢!

解决方案

由于来电是来电,请打开浏览器窗口并转到网址。 将收到的json复制回剪贴板。



在名为WeatherData的项目中添加一个新类。   突出显示课程定义并转到编辑菜单 - >粘贴特殊 - >将json粘贴为类



然后在项目中添加NuGet包Newtonsoft.json。   这样的代码会将您从webclient或httpclient返回的json反序列化为类


 

  Dim weather As WeatherData = JsonConvert.DeserializeObject(Of WeatherData)(json) 



Hello,

What would be the best way to get and display the values of a JSON file. The files I am trying to read can be found at:

https://api.weather.gov/zones/forecast/KSZ015/forecast

https://api.weather.gov/stations/KICT/observations/latest

Where the KSZ015 and KICT are they will be replaced with a {TextBox3.Text} so the user can input the information for their location.

I tried to convert them to XML files using the method given by the NWS but they do not offer these two features in XML form only JSON. I can get weather alerts in XML which I have successfully done.

How can I get the information from the JSON feeds and display each piece of information (temperature, text description, dew point, humidity, etc.) and forecasts for a specific day or number of days?

Thank You!

解决方案

Since the call is a get call open up a browser window and go to the url.  Copy the json recieved back into the clipboard.

Add a new class to the project called WeatherData.   Highlight the class definition and goto to the edit menu --> paste special --> paste json as classes

Then in your project you can add the NuGet package Newtonsoft.json.   Code like this will deserialize the json you go back from the webclient or httpclient into a class

Dim weather As WeatherData = JsonConvert.DeserializeObject(Of WeatherData)(json)



这篇关于在Visual Basic中使用JSON文件从API获取天气信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆