rust中使用Reqwest解析JSON
Cargo.toml
serde_json = "1.0"
serde = "1.0"
serde_derive = "1.0"
1、引入serde_derive
#[macro_use]
extern crate serde_derive;
2、按照目标json定义结构体
#[derive(Deserialize, Debug)]
struct Forecast {
time: String,
values: Vec<f32>,
status: String,
uptime: String,
msg: String,
}
3、解析
let res: Forecast = reqwest::get(RAIN_API).unwrap().json().unwrap();
println!("{:#?}", res.msg);