Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::fs::File;
- use std::io;
- use std::io::prelude::*;
- use serde_derive::*;
- use serde_json;
- const JSON_FILE: &'static str = r#"
- {
- "users": [
- {
- "id": "49824073-979f-4814-be10-5ea416ee1c2f",
- "username": "john_doe"
- },
- {
- "id": "97c4ef58-04f2-4320-a652-2974819b912c",
- "username": "jane_doe"
- },
- ]
- }
- "#;
- #[derive(Debug, Serialize, Deserialize)]
- struct Users {
- id: u8,
- username: String,
- }
- fn main() {
- let content: Users = serde_json::from_str(JSON_FILE).unwrap();
- dbg!(content);
- }
- /*
- Error missing field 'id'
- unable to get users.id and users.name */
Add Comment
Please, Sign In to add comment