Guest User

Untitled

a guest
Feb 17th, 2019
612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. use std::fs::File;
  2. use std::io;
  3. use std::io::prelude::*;
  4.  
  5. use serde_derive::*;
  6. use serde_json;
  7.  
  8. const JSON_FILE: &'static str = r#"
  9. {
  10. "users": [
  11. {
  12. "id": "49824073-979f-4814-be10-5ea416ee1c2f",
  13. "username": "john_doe"
  14. },
  15. {
  16. "id": "97c4ef58-04f2-4320-a652-2974819b912c",
  17. "username": "jane_doe"
  18. },
  19. ]
  20. }
  21. "#;
  22.  
  23.  
  24. #[derive(Debug, Serialize, Deserialize)]
  25. struct Users {
  26. id: u8,
  27. username: String,
  28. }
  29.  
  30. fn main() {
  31. let content: Users = serde_json::from_str(JSON_FILE).unwrap();
  32. dbg!(content);
  33. }
  34.  
  35. /*
  36. Error missing field 'id'
  37. unable to get users.id and users.name */
Add Comment
Please, Sign In to add comment