How to convert Unicode to JavaScript?

I am using the Google Maps API. See This JSON Answer .

HTML instructions are written as follows:

"html_instructions" : "Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eEnggårdsgade\u003c/b\u003e" 

How can I convert Unicode \u003c , \u003e , etc. in javascript?

+6
source share
3 answers

These are Unicode escape sequences in a JavaScript string. As for JavaScript, it is the same character.

 '\u003cb\u003eleft\u003c/b\u003e' == '<b>left</b>'; // true 

So, you do not need to do any conversion at all.

+9
source

you can use JSON.parse directly on the JSON response, then Unicode characters will be automatically converted to its html countable parts (\ u003c will be converted to <sign to html)

 JSON.parse(JSON.stringify({a : 'Turn \u003cb\u003eleft\u003c/b\u003e onto \u003cb\u003eEnggårdsgade\u003c/b\u003e'})); 
+4
source

This little feature can help.

 String.prototype.toUnicode = function(){ var hex, i; var result = ""; for (i=0; i<this.length; i++) { hex = this.charCodeAt(i).toString(16); result += ("\\u00"+hex).slice(-7); } return result; }; 
0
source

Source: https://habr.com/ru/post/911976/


All Articles