Home >Web Front-end >JS Tutorial >js unicode encoding analysis on two methods of converting data to Chinese_javascript skills

js unicode encoding analysis on two methods of converting data to Chinese_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:51:491320browse
Copy code The code is as follows:

var str = "\u6211\u662Funicode\u7F16\u7801";

Regarding the problem of converting such data into Chinese, there are two commonly used methods.

1. eval parsing
Copy code The code is as follows:

str = eval("'" str "'"); // "I am unicode encoding"

2. unescape parsing
Copy code The code is as follows:

str = unescape(str.replace(/\u/g, "%u")); // "I am unicode encoding"

Little knowledge points, record and share
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn