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);
}
}
How can the value of object key "a"
be transformed into the following string?
b\u{1f}c
I've tried with serde_json
and str::from_utf8
, but I always get "b\u001fc"
as the result. The escaped character sequence is not interpreted correctly. How this can be solved?