Browse Source

feat: serde json demo

dev
Dnomd343 2 years ago
parent
commit
e34ddf3d0a
  1. 33
      to-json/Cargo.lock
  2. 2
      to-json/Cargo.toml
  3. 21
      to-json/src/main.rs

33
to-json/Cargo.lock

@ -2,6 +2,39 @@
# It is not intended for manual editing.
version = 3
[[package]]
name = "itoa"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc"
[[package]]
name = "ryu"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09"
[[package]]
name = "serde"
version = "1.0.145"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "728eb6351430bccb993660dfffc5a72f91ccc1295abaa8ce19b27ebe4f75568b"
[[package]]
name = "serde_json"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "41feea4228a6f1cd09ec7a3593a682276702cd67b5273544757dae23c096f074"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "to-json"
version = "0.1.0"
dependencies = [
"serde",
"serde_json",
]

2
to-json/Cargo.toml

@ -6,3 +6,5 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
serde = "1.0.145"
serde_json = "1.0.86"

21
to-json/src/main.rs

@ -1,3 +1,22 @@
use serde_json::{Value};
fn json_str() -> String {
let json = r#"{
"demo": "key_1",
"author": "dnomd343",
"test": [
"123",
"234",
"345"
]
}"#;
return String::from(json);
}
fn main() {
println!("Hello, world!");
let raw = json_str();
println!("JSON raw content ->\n{}", raw);
let parsed: Value = serde_json::from_str(&raw[..]).unwrap();
println!("Author -> {}", parsed["author"]);
}

Loading…
Cancel
Save