I'm querying an API over HTTP I'm getting back JSON data with following
... Dv\\u016fr Kr\\u00e1lov\\u00e9 nad Labem a okol\\u00ed 5\\u00a0km ...".
This is what I see when I open the same request in Firefox and show raw data and also when I try to println! the output in Rust.
I would like Rust to rather interpret these into proper chars. I've tried following function which I've googled and it works partially but it fails for some chars
pub fn normalize(json: &str) -> core::result::Result<String, Box<dyn Error>> {
let replaced : Cow<'_, str> = regex_replace_all!(r#"\\u(.{4})"#, json, |_, num: &str| {
let num: u32 = u32::from_str_radix(num, 16).unwrap();
let c: char = std::char::from_u32(num).unwrap();
c.to_string()
});
Ok(replaced.to_string())
}
Dvůr Králové nad Labem a okolí 5\u{a0}km
What's the proper way to handle such JSON data?