pub struct JsonWrapper {
pub raw_data: String,
pub data: Value,
}Expand description
Json 数据读取
use dev_tool::JsonWrapper;
#[test]
fn test_config_util() {
// 读取配置文件
let wrapper = JsonWrapper::new("docs/config.json").unwrap();
// 直接将json字符串转换成JsonWrapper
// let warpper = JsonWrapper::from_string("......").unwrap();
// 不管是对象,还是数组,都是直接通过`.`操作。address是对象,children是数组,name是children中对象的一个属性
let x = wrapper.get("address.children.name");
println!("address.children.name = {:?}", x);
// get方法是获取数组,而get_one获取的是第一个元素
let x = wrapper.get_one("address.x.y").as_str().unwrap();
println!("address.x.y = {}", x);
}Fields§
§raw_data: String§data: ValueImplementations§
Trait Implementations§
Auto Trait Implementations§
impl Freeze for JsonWrapper
impl RefUnwindSafe for JsonWrapper
impl Send for JsonWrapper
impl Sync for JsonWrapper
impl Unpin for JsonWrapper
impl UnwindSafe for JsonWrapper
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more