Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save stianeklund/cd1790fb1d687900e40f2c86c4d32eed to your computer and use it in GitHub Desktop.
Save stianeklund/cd1790fb1d687900e40f2c86c4d32eed to your computer and use it in GitHub Desktop.
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