多层级嵌套类型的 json 会被解析为内置的 Map 类型(object),需要多次迭代解析。

    1. use serde_json::{Map, Value};
    2. fn main() {
    3. let str = r#"{"title":"xxx", "content":"abc", "keyboard":{"name":"tom", "email":"aa@qq.com"}, "ctime": 111111}"#;
    4. let parsed: Value = serde_json::from_str(str).unwrap();
    5. let obj: &Map<String, Value> = parsed.as_object().unwrap();
    6. for (key, val) in obj {
    7. if key == "keyboard" {
    8. for (k, v) in val.as_object().unwrap() {
    9. println!("o:{}|{}", k, v);
    10. }
    11. }
    12. }
    13. println!("a:{:?}", obj);
    14. }