Closed H1rono closed 1 year ago
src/main.rs
use std::error::Error;
use std::io::Read;
use traq::models::UserDetail;
fn main() -> Result<(), Box<dyn Error>> {
let mut stdin = std::io::stdin().lock();
let mut buff = Vec::new();
stdin.read_to_end(&mut buff)?;
let content = String::from_utf8(buff)?;
let u: UserDetail = serde_json::from_str(&content)?;
println!("user: {}", serde_json::to_string_pretty(&u)?);
Ok(())
}
testdata.json
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"state": 0,
"bot": true,
"iconFileId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"displayName": "string",
"name": "rDpDFbtRGP73OLgrBxTCLewgEJlZViq",
"twitterId": "IhUDsKmzOI4aaFK",
"lastOnline": "2023-07-20T13:22:25.995Z",
"updatedAt": "2023-07-20T13:22:25.995Z",
"tags": [
{
"tagId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"tag": "string",
"isLocked": true,
"createdAt": "2023-07-20T13:22:25.995Z",
"updatedAt": "2023-07-20T13:22:25.995Z"
}
],
"groups": [
"3fa85f64-5717-4562-b3fc-2c963f66afa6"
],
"bio": "string",
"homeChannel": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
shell
$ cat testdata.json | cargo run
...
Error: Error("expected value", line: 3, column: 14)
ここが問題
serde(rename = "0")
だと整数の0
ではなく文字列の"0"
を受け付けるため
serde-reprを使うのが丸そう
↓
他にも動かないやつがあるかも