简体   繁体   中英

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. The response is from a cryptocurrency websocket api. I generally use pako but am unable to get pako inflate the below

Response

[""]

Thank you

To use pako you must first convert your data from a hexadecimal string to a byte array. 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM