簡體   English   中英

Rocket無法解析JSON

[英]Rocket cannot parse JSON

嘗試用火箭解析 JSON 時出現錯誤。 這是我的代碼:

extern crate serde;
use rocket::serde::{json::Json, Deserialize};
use serde::Serialize;
#[macro_use]
extern crate rocket;
mod eth;
mod rocket_test;

#[launch]
fn rocket() -> _ {
    rocket::build().mount("/task", routes![body])
}
#[derive(Serialize, Deserialize)]
struct Message2 {
    id: usize,
}

#[post("/", format = "json", data = "<message>")]
async fn body(message: Json<Message2>) -> &'static str {
    "Fine"
}

這是我的 toml 文件:

[dependencies]
serde = {version = "1.0", features = ["derive"]}
serde_derive = "1.0"
serde_json = "1.0"
tester = "0.9.0"
tokio = {version = "1", features = ["full"]}

[dependencies.rocket]
features = ["json"]
version = "0.5.0-rc.1"

我收到此錯誤

thread 'rocket-worker-thread' panicked at 'assertion failed: `(left == right)`
  left: `0x28f12470657`,
 right: `0x28f12470640`', C:\Users\gadum\.cargo\registry\src\github.com-1ecc6299db9ec823\tokio-1.16.0\src\io\util\take.rs:93:9
note: run with `RUST_BACKTRACE=1` environment variable 
to display a backtrace
   >> Handler body panicked.

與解析 JSON 的示例相同。 但我不知道出了什么問題。 我正在使用 VSCode Rest 客戶端發送請求,就像這樣

POST http://127.0.0.1:8000/task
content-type: application/json

{
    "id": 10
}

看起來1.16.0版的tokio有一個錯誤: https://github.com/tokio-rs/tokio/issues/4435

進行cargo update ,它應該將您的依賴項更新為1.16.1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM