[英]Javascript decode hex string with backslash
I got the hex string from sever:我从服务器得到了十六进制字符串:
const res = {"data": "\\xf0\\x9d\\x90\\x81"};
The original text is:原文是:
I'm used decodeURIComponent and escape function got:我使用 decodeURIComponent 和转义 function 得到:
decodeURIComponent(escape(res.data));
// "\xf0\x9d\x90\x81"
How to decode hex string with double backslash?如何用双反斜杠解码十六进制字符串?
Just a little sample for u.只是给你一个小样本。 Hope it works!!希望它有效!
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var uri_enc = '\\xf0\\x9d\\x90\\x81';
var uri_dec= decodeURIComponent(uri_enc.replace(/\\x/g, '%'));
var res = "Encoded URI: " + uri_enc + "<br>" + "Decoded URI: " + uri_dec;
document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>
Result will be like this:结果将是这样的:
Encoded URI: \xf0\x9d\x90\x81
Decoded URI: 𝐁
If not working tell us, we will share more solutions!!如果不起作用告诉我们,我们将分享更多解决方案!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.