use serde_json::json; // 1.0.66
use std::str;
fn main() {
let input = "{\"a\": \"b\\u001fc\"}";
let bytes = input.as_bytes();
let json: serde_json::Value = serde_json::from_slice(bytes).unwrap();
for (_k, v) in json.as_object().unwrap() {
let vec = serde_json::to_vec(v).unwrap();
let utf8_str = str::from_utf8(&vec).unwrap();
println!("value: {}", v);
println!("utf8_str: {}", utf8_str);
println!("bytes: {:?}", vec);
}
}
对象键的值如何"a"
转化为下面的字符串?
b\u{1f}c
我试过serde_json
and str::from_utf8
,但我总是得到"b\u001fc"
结果。转义字符序列未正确解释。如何解决?