[英]Inflate response from websocket API
I am getting the following message from a websocket endpoint and would like to know how to inflate the message and get a json. 我正在从websocket端点获取以下消息,并且想知道如何对消息进行充气并获取json。 The response is from a cryptocurrency websocket api.
响应来自加密货币websocket api。 I generally use pako but am unable to get pako inflate the below
我通常使用pako,但无法将pako充气到下面
Response 响应
[""] [ “”]
Thank you 谢谢
To use pako
you must first convert your data from a hexadecimal string to a byte array. 要使用
pako
您必须首先将数据从十六进制字符串转换为字节数组。 Here's one way to do this: 这是执行此操作的一种方法:
function decodeHex(hexString) {
let result = new Uint8Array(hexString.length / 2);
for (let i = 0; i < result.length; i++) {
result[i] = parseInt(hexString.slice(2 * i, 2 * i + 2), 16);
}
return result;
}
let json = pako.inflate(decodeHex("your string"),
{ to: 'string' });
let decoded = JSON.parse(json);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.