初学 rust 的新手,在不将 JSON 字符串解析到结构体的情况下,如何方便的读取 JSON 对象的 A.B.C 的值? 目前我的实现方式:
let data: Value = serde_json::from_str(response.as_str())?;
let records = data
.get("A")
.ok_or_else(|| io::Error::new(ErrorKind::Other, "missing field: A"))?
.get("B")
.ok_or_else(|| io::Error::new(ErrorKind::Other, "missing field: B"))?
.get("C")
.ok_or_else(|| io::Error::new(ErrorKind::Other, "missing field: C"))?
请问大家有没有方法可以省略掉这些 ok_or_else()调用?