admin管理员组文章数量:1425668
Supposing I have a string of code like so:
\u00e5\u00b1\u00b1\u00e4\u00b8\u008a\u00e7\u009a\u0084\u00e4\u00ba\u00ba
How would I convert these back into Chinese characters using Javascript:
山上的人
This is so that I can actually display Chinese on my web page. Right now it es out as å±±ä¸ç人
.
This website manages to acplish this, however this is with PHP they don't expose.
I am not familiar with how character encoding works well at all, so I don't even know the terminology to search for a proper solution.
Supposing I have a string of code like so:
\u00e5\u00b1\u00b1\u00e4\u00b8\u008a\u00e7\u009a\u0084\u00e4\u00ba\u00ba
How would I convert these back into Chinese characters using Javascript:
山上的人
This is so that I can actually display Chinese on my web page. Right now it es out as å±±ä¸ç人
.
This website manages to acplish this, however this is with PHP they don't expose.
I am not familiar with how character encoding works well at all, so I don't even know the terminology to search for a proper solution.
Share Improve this question edited Jan 15, 2018 at 2:28 dthree asked Jan 15, 2018 at 2:18 dthreedthree 20.8k14 gold badges80 silver badges113 bronze badges 7- Possible duplicate of stackoverflow./questions/3745666/… – Devan Buggay Commented Jan 15, 2018 at 2:20
- The code from that post doesn't do the trick. – dthree Commented Jan 15, 2018 at 2:21
- Ah perhaps this one is more relevant: stackoverflow./questions/21647928/… – Devan Buggay Commented Jan 15, 2018 at 2:24
- 2 @dthree—that is result of literal conversion of control code (\u00e5) to code point (229) to character (å). – RobG Commented Jan 15, 2018 at 3:40
-
1
JavaScript internally only works with UCS-2 (where 山 is
\u5C71
), and doesn't understand UTF-8 (\xE5\xB1\xB1
). Moreover,\u00e5\u00b1\u00b1
is likely wrong due to extra zeroes, probably. Thus it would be good to give it data in the proper form in the first place, rather than try to transform it (but if you absolutely need to do that, Steven Tang's answer seems to be good). Where is your data ing from? – Amadan Commented Jan 15, 2018 at 5:27
2 Answers
Reset to default 2The string appears to be in UTF-8.
https://github./mathiasbynens/utf8.js is a helpful Javascript library that saves you the headache of learning the UTF-8 standard, and will decode the UTF-8 into text.
Here's a demo: https://mothereff.in/utf-8
Paste in \u00e5\u00b1\u00b1\u00e4\u00b8\u008a\u00e7\u009a\u0084\u00e4\u00ba\u00ba
into the "UTF-8-encoded" textarea to decode it.
Add <meta charset="UTF-8">
inside the <head></head>
tag of your HTML file so that it will display Chinese properly. Just put the Chinese characters directly in your HTML file
本文标签: javascriptConvert unicode to Chinese charactersStack Overflow
版权声明:本文标题:javascript - Convert unicode to Chinese characters - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745394539a2656752.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论