Cargo.toml
[dependencies]
reqwest = { version = "0.10.0-alpha.2", features = ["blocking"] }
使用了最新的版本
main.rs
extern crate reqwest;
use serde::{Deserialize, Serialize};
#[derive(Deserialize)]
struct Ip {
origin: String,
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp: Ip = reqwest::blocking::get("https://httpbin.org/ip")?
.json()?;
println!("{:?}", resp.origin);
Ok(())
}
编译报错
error[E0599]: no method named `json` found for type `reqwest::blocking::Response` in the current scope
--> src/main.rs:13:10
|
13 | .json()?;
| ^^^^ method not found in `reqwest::blocking::Response`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0599`.
是Github上的官方示例有问题,还是我哪里没有引入包导致的
搜索一圈没看到相关的报错
提前感谢,走过路过帮忙解答一下 :)
1
共 3 条评论, 1 页
评论区
写评论十分感谢,添加后解决了问题。
对以下内容的回复:
reqwest = { version = "0.10.0-alpha.2", features = ["blocking","json"] } 对以下内容的回复:
在Cargo.toml启用reqwest的json feature