如何将actix_web::web::Bytes转换成json?

How to convert actix_web::web::Bytes to json?

这是我的代码:

#[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);


}

此代码有效,但我不知道如何将类型 actix_web::web::Byte 转换为 json。

我试过转换 json:

    let result = response
        .unwrap()
        .json::<HashMap<String, std::marker::PhantomData<String>>>()
        .await;

但每次我都会收到错误消息,因为 HashMap 具有混合类型。它是 HashMap.

所以我的问题是:

如何将响应转换为 json?

我正在使用 use actix_web::client::Client

您可以使用serde_json::value::Value

use serde_json::value::Value;

...

let result = response
        .unwrap()
        .json::<HashMap<String, Value>>()
        .await;