I have this so far in my goal to Parse this JSON data in Rust:
extern crate rustc_serialize;
use rustc_serialize::json::Json;
use std::fs::File;
use std::io::copy;
use std::io::stdout;
fn main() {
let mut file = File::open("text.json").unwrap();
let mut stdout = stdout();
let mut str = ©(&mut file, &mut stdout).unwrap().to_string();
let data = Json::from_str(str).unwrap();
}
and text.json
is
{
"FirstName": "John",
"LastName": "Doe",
"Age": 43,
"Address": {
"Street": "Downing Street 10",
"City": "London",
"Country": "Great Britain"
},
"PhoneNumbers": [
"+44 1234567",
"+44 2345678"
]
}
What should be my next step into parsing it? My primary goal is to get JSON data like this, and parse a key from it, like Age.
let obj = data.as_object().unwrap();
and gotthread '<main>' panicked at 'called
Option::unwrap()` on aNone
value', C:/bo t/slave/stable-dist-rustc-win-32/build/src/libcore\option.rs:362 }An unknown error occurred` – Shores