История изменений
Исправление
RazrFalcon,
(текущая версия)
:
extern crate serde_json;
#[macro_use] extern crate serde_derive;
#[derive(Deserialize, Debug)]
struct Foo {
number: Option<i32>,
#[serde(rename = "str")]
name: String,
}
fn main() {
let text = r#"{"number": 12, "str": "hello"}"#;
let v: Foo = serde_json::from_str(text).unwrap();
println!("{:?}", v); // Foo { number: Some(12), name: "hello" }
}
Исходная версия
RazrFalcon,
:
extern crate serde_json;
#[macro_use] extern crate serde_derive;
#[derive(Deserialize, Debug)]
struct Foo {
number: Option<i32>,
#[serde(rename = "str")]
name: String,
}
fn main() {
let text = r#"{"number": 12, "str": "hello"}"#;
let v: Foo = serde_json::from_str(text).unwrap();
println!("{:?}", v); // Foo { number: Some(12), name: "hello" }
}