Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use serde::{Deserialize, Serialize};
- use std::collections::HashMap;
- use serde_json::Result;
- #[derive(Debug, Deserialize)]
- struct InThing {
- prop_one: String,
- decimals: u16,
- }
- #[derive(Debug, Deserialize)]
- struct OutThing {
- error: Vec<u8>,
- result: HashMap<String, InThing>,
- }
- fn main() {
- let data = r#"
- {
- "error": [],
- "result": {
- "NAME_X": {
- "prop_one": "something",
- "prop_two": "something",
- "decimals": 1,
- "more_decimals": 2
- },
- "NAME_A": {
- "prop_one": "test",
- "prop_two": "sdfsdf",
- "decimals": 2,
- "more_decimals": 5
- },
- "ARBITRARY": {
- "prop_one": "something else",
- "prop_two": "blah",
- "decimals": 3,
- "more_decimals": 6
- }
- }
- }
- "#;
- let thing: OutThing = serde_json::from_str(data).unwrap();
- dbg!(thing);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement