Created
July 18, 2016 16:00
-
-
Save stianeklund/cd1790fb1d687900e40f2c86c4d32eed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn main() { | |
let path = Path::new("/home/stian/projects/rosten/tracking.json"); | |
let display = path.display(); | |
let mut file = match File::open(&path) { | |
Err(e) => panic!("unable to open {}: {}", display, e.description()), | |
Ok(file) => file, | |
}; | |
let mut buffer = String::new(); | |
file.read_to_string(&mut buffer).unwrap(); | |
let data: Value = serde_json::from_str(&buffer).unwrap(); | |
let obj = data.as_object().unwrap(); | |
for (key, value) in obj.iter() { | |
println!("{}: {}", key, match *value { | |
Value::String(ref v) => format!("{} (string)", v), | |
Value::U64(v) => format!("{} (u64)", v), | |
_ => format!("other match") | |
}); | |
} | |
} | |
// This is a sample of the JSON file.. I'm having problems reading beyond consignmentSet and my match returns ("other match") | |
{ | |
"consignmentSet": [ | |
{ | |
"consignmentId": "SHIPMENTNUMBER", | |
"previousConsignmentId": "", | |
"packageSet": [ | |
{ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment