I am expecting to get a string containing non ascii chars, for eg. the string Øvo
, but the string I get instead contains a different representation of that char: Ã\vo
. How can I convert this to the string I want?
I know how this string represention is obtained but I can't undo that encoding:
let modelString = JSON.stringify(model);
return window.btoa(unescape(encodeURIComponent(modelString)));
I have been trying a lot of functions (from Firefox console) but I'm not getting the expected result:
Avoid using unescape
as it is "removed from the Web standards"!
var model = {"key": "Øvo"}; var modelString = JSON.stringify(model); var uriEncoded = encodeURIComponent(modelString); console.log(uriEncoded); // wrong console.log(unescape(uriEncoded)); // right console.log(decodeURIComponent(uriEncoded)); // btoa convertion var b2a = btoa(decodeURIComponent(uriEncoded)); console.log(b2a); // the reverse conversion var a2b = atob(b2a); console.log(a2b);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.