Reputation: 33071
This is my code:
#[actix_web::main]
async fn main() -> std::io::Result<()> {
let mut client = Client::default();
// Create request builder and send request
let response = client
.get("https://ipapi.co/localhost/json")
.header("User-Agent", "actix-web/3.0")
.send() // <- Send request
.await; // <- Wait for response
let result = response.unwrap().body().await.unwrap();
println!("Response: {:?}", result);
}
This code works, but I don't know how to convert type actix_web::web::Byte
to json.
I have tried to convert it ti json:
let result = response
.unwrap()
.json::<HashMap<String, std::marker::PhantomData<String>>>()
.await;
But every time I'm receiving an error, because HashMap has mixed types. It is HashMap<String, bool|String|i32>.
So my question is:
How to convert response to json?
I'm using use actix_web::client::Client
.
Upvotes: 1
Views: 1491
Reputation: 42716
You can use serde_json::value::Value
use serde_json::value::Value;
...
let result = response
.unwrap()
.json::<HashMap<String, Value>>()
.await;
Upvotes: 2