Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. use serde::{Deserialize, Serialize};
  2. use std::collections::HashMap;
  3. use serde_json::Result;
  4.  
  5. #[derive(Debug, Deserialize)]
  6. struct InThing {
  7. prop_one: String,
  8. decimals: u16,
  9. }
  10. #[derive(Debug, Deserialize)]
  11. struct OutThing {
  12. error: Vec<u8>,
  13. result: HashMap<String, InThing>,
  14. }
  15.  
  16. fn main() {
  17. let data = r#"
  18. {
  19. "error": [],
  20. "result": {
  21. "NAME_X": {
  22. "prop_one": "something",
  23. "prop_two": "something",
  24. "decimals": 1,
  25. "more_decimals": 2
  26. },
  27. "NAME_A": {
  28. "prop_one": "test",
  29. "prop_two": "sdfsdf",
  30. "decimals": 2,
  31. "more_decimals": 5
  32. },
  33. "ARBITRARY": {
  34. "prop_one": "something else",
  35. "prop_two": "blah",
  36. "decimals": 3,
  37. "more_decimals": 6
  38. }
  39. }
  40. }
  41. "#;
  42. let thing: OutThing = serde_json::from_str(data).unwrap();
  43. dbg!(thing);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement