extern crate openweather;
use openweather::LocationSpecifier;
static API_KEY: &str = "e85e0a3142231dab28a2611888e48f22";
fn main() {
let loc = LocationSpecifier::Coordinates {
lat: 24.87,
lon: 67.03,
};
let weather = openweather::get_current_weather(loc, API_KEY).unwrap();
print!(
"Right now in Minneapolis, MN it is {}K",
weather.main.humidity
);
}
错误:线程“main”在调用<code>Result::unwrap()
问题是由于反序列化结构与OpenWeather的JSON不匹配而导致的JSON解析错误,也许API最近添加了这个?在您的示例中,OpenWeatherCurrent 结构缺少时区
。
但看起来有一个开放的PR可以解决这个问题,您可以通过执行以下操作来测试它:
>
货物。toml
依赖于openweather={git=”https://github.com/caemor/openweather“}
PR作者还更新了get_current_weather
签名,因此您需要将第2行、第10行更改为以下内容:
use openweather::{LocationSpecifier, Settings};
let weather = openweather::get_current_weather(&loc, API_KEY, &Settings::default()).unwrap();