In my application I have to use scientific unit such as m³/h
. So that I store that Unicode in my database like m\u00b3/h
. But the problem is, when I fetch data from API, it returns this with addition \
like "sign": "m\\u00b3/h"
. Is there any way to get rid off this issue.
I store the Unicode in DB like this:
When I fetch this, It returns me like this:
And I use this in my UI Like this:
Please help.
CodePudding user response:
That extra \
it's just to escape that special character from JSON. If you're using a JSON library, it will escape it automatically.
If not you can use this:
('m\\u00b3/h').replace('\\\\', '\\');
CodePudding user response:
x = 'm\\u00b3/h';
x.replace(/\/\//g, "") // should output m\u00b3/h
Also, if you want to convert unicode to HTML, use this
x = 'm\\u00b3/h';
JSON.parse('"' x '"') // Should output 'm³/h'