1 几个对象
- 字符串:
r#"{ "name": "John Doe"}"#
serde_json::Value
: json内部结构struct Person{name: String}
: rust内部结构
2 转换
2.1 字符串 –> Value
1 | let data = r#"{ "name": "John Doe"}"#; |
2.2 字符串 –> struct
1 | let data = r#"{ "name": "John Doe"}"#; |
2.3 Value –> 字符串
1 | let v = json!({"name":"hi"}); |
2.4 Value –> struct
1 | let p:Persion = serde_json::from_value(jv)?; |
2.5 struct –> 字符串
1 | let j:String = serde_json::to_string(&person)?; |
2.6 struct –> Value
1 | let jv: Value = serde_json::to_value(person)?; |
3 修改
1 | jv["a"] = json!("world"); |