2

Why reqwest return error while trying to .json() the response? Looks like im trying the same as in an example:

fn main() -> Result<(), Box<dyn std::error::Error>> {
let resp = reqwest::blocking::get("https://pokeapi.co/api/v2/pokemon/1")?.json()?;
println!("{:?}", resp);
Ok(())
}

When i do text() instead of json() i get string as intended, but i can't seem to parse it to json. Thanks.

Error: Error: reqwest::Error { kind: Decode, source: Error("invalid type: map, expected unit", line: 1, column: 0) }

Kamil Staszewski
  • 303
  • 7
  • 20
  • 1
    As [documented](https://docs.rs/reqwest/0.11.1/reqwest/blocking/struct.Response.html#method.json): *"This method fails whenever the response body is not in JSON format or it cannot be properly deserialized to target type `T`."* It doesn't appear that you are providing type information for the deserializer to work, and it assumes the unit type `()`, which apparently doesn't match the JSON content. – IInspectable Mar 03 '21 at 19:28

0 Answers0