Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
Unescape Unicode char in javascript

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: Ã\u0098vo. 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:

  • window.atob(escape(decodeURIComponent('Ã\u0098vo'))) -> Uncaught DOMException: String contains an invalid character
  • escape(decodeURIComponent('Ã\u0098vo')) -> "%C3%98vo"
  • JSON.parse('["Ã\u0098vo"]')[0] -> "Ã\u0098vo"
  • JSON.parse('["Ã\u0098vo"]')[0] -> "Ã\u0098vo"
  • unescape('Ã\u0098vo') -> "Ã\u0098vo"
  • unescape('Ã\u0098vo') -> "Ã\u0098vo"
  • String.fromCharCode(parseInt('98',64)) -> "\u0000"
  • String.fromCharCode(parseInt('98')) -> "b"
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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);

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda