火箭无法解析 JSON
Rocket cannot parse JSON
我在尝试使用 rocket 解析 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
}
tokio
的 1.16.0
版本似乎有错误:https://github.com/tokio-rs/tokio/issues/4435
执行 cargo update
它应该将您的依赖项更新为 1.16.1
。
我在尝试使用 rocket 解析 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
}
tokio
的 1.16.0
版本似乎有错误:https://github.com/tokio-rs/tokio/issues/4435
执行 cargo update
它应该将您的依赖项更新为 1.16.1
。