implement lookup method for json::Value

This commit is contained in:
Jorge Israel Peña
2015-05-17 21:24:00 -07:00
parent ee45eb8340
commit bc236bde34
2 changed files with 25 additions and 0 deletions
+9
View File
@@ -1065,3 +1065,12 @@ fn test_missing_fmt_renamed_field() {
))).unwrap();
assert_eq!(value, Foo { x: Some(5) });
}
#[test]
fn test_lookup() {
let obj: Value = json::from_str(r#"{"x": {"a": 1}, "y": 2}"#).unwrap();
assert!(obj.lookup("x.a").unwrap() == &Value::U64(1));
assert!(obj.lookup("y").unwrap() == &Value::U64(2));
assert!(obj.lookup("z").is_none());
}