Is there a command line tool or online service that can convert javascript unicode notation code to utf-8?
E.g. I got this json code, but it is hard to edit in common text editor.
{"name":"leon zhang","city":"\u4e0a\u6d77"}
I want to convert it to:
{"name":"leon zhang","city":"上海"}
Click Tools, then select Web options. Go to the Encoding tab. In the dropdown for Save this document as: choose Unicode (UTF-8). Click Ok.
While a JavaScript source file can have any kind of encoding, JavaScript will then convert it internally to UTF-16 before executing it. JavaScript strings are all UTF-16 sequences, as the ECMAScript standard says: When a String contains actual textual data, each element is considered to be a single UTF-16 code unit.
Most JavaScript engines use UTF-16 encoding, so let's detail into UTF-16. UTF-16 (the long name: 16-bit Unicode Transformation Format) is a variable-length encoding: Code points from BMP are encoded using a single code unit of 16-bit. Code points from astral planes are encoded using two code units of 16-bit each.
Unicode in Javascript source code In Javascript, the identifiers and string literals can be expressed in Unicode via a Unicode escape sequence. The general syntax is \uXXXX , where X denotes four hexadecimal digits. For example, the letter o is denoted as '\u006F' in Unicode.
You use the below javascript function to convert unicode to utf-8
function encode_utf8( s ){
return unescape( encodeURIComponent( s ) );
}( '\u4e0a\u6d77' )
You can also try it out in firebug console. It works.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With