NodeJS decodeURIComponent无法正常工作 [英] NodeJS decodeURIComponent not working properly

查看:2709
本文介绍了NodeJS decodeURIComponent无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用decodeURLCompnent解码下面的字符串:

When I tryed to decode the string below in nodeJS using decodeURLCompnent:

var decoded = decodeURI('Ulysses%20Guimar%C3%A3es%20-%20lado%20par');
console.log(decoded);

我得到

Ulysses Guimarães - lado par

而不是

Avenida Ulysses Guimarães - lado par 

但是当我在客户端(浏览器)上使用相同的代码时,我可以得到正确的字符'ã'。

But when I use the same code on the client side (browser) I can get the right char 'ã'.

>

推荐答案

我无法重现它在节点的0.10或0.11版本中。

I cannot reproduce it in 0.10 or 0.11 versions of node.

您可以使用 new Buffer('UlyssesGuimarães - lado par'二进制')。toString('utf8'),但它是一个解决方法,而不是解决方案。

You can convert first to second using new Buffer('Ulysses Guimarães - lado par', 'binary').toString('utf8'), but it's a workaround, not a solution.

,不退出?

这篇关于NodeJS decodeURIComponent无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆