我正在使用Javascript window.atob()函数来解码base64编码的字符串(特别是GitHub API中的base64编码内容).问题是我得到了ASCII编码的字符(â¢而不是™).如何正确处理传入的base64编码流,以便将其解码为utf-8?
我在JavaScript中处理utf-8字符串并需要转义它们.
escape()/ unescape()和encodeURI()/ decodeURI()都可以在我的浏览器中使用.
逃逸()
> var hello = "?????"
> var hello_escaped = escape(hello)
> hello_escaped
"%uC548%uB155%uD558%uC138%uC694"
> var hello_unescaped = unescape(hello_escaped)
> hello_unescaped
"?????"
Run Code Online (Sandbox Code Playgroud)
是encodeURI()
> var hello = "?????"
> var hello_encoded = encodeURI(hello)
> hello_encoded
"%EC%95%88%EB%85%95%ED%95%98%EC%84%B8%EC%9A%94"
> var hello_decoded = decodeURI(hello_encoded)
> hello_decoded
"?????"
Run Code Online (Sandbox Code Playgroud)
虽然encodeURI()和decodeURI()使用上面的utf-8字符串,但docs(以及函数名称本身)告诉我这些方法适用于URI; 我没有看到任何地方提到的utf-8字符串.
简单地说,对于utf-8字符串使用encodeURI()和decodeURI()是否可以?