You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解码API返回的Gzip压缩Payload以获取二维矩阵

解码Gzip压缩数组获取二维矩阵的解决方案

核心逻辑

  1. 将API返回的payload一维整数数组转换为字节流
  2. 使用Gzip算法解压字节流
  3. 将解压后的数据解析为目标二维矩阵(通常是JSON格式,或按特定二进制规则解析)

Python 实现示例

import gzip
import json
from io import BytesIO

# API返回的响应数据
api_response = {
    "isPacked": True,
    "payload": [31,139,8,0,0,0,0,0,0,3,117,83,205,110,219,48,12,126,23,158,221,64,146,37,89,214,109,43,48,160,91,119,217,114,105,135,98,144,109,37,49,42,91,129,44,247,7,129,129,157,247,14,123,136,189,210,78,123,140,81,110,210,116,69,106,24,130,77,126,36,63,242,163,118,16,236,48,186,8,58,134,209,102,80,153,24,157,29,64,127,219,65,59,124,49,206,61,30,92,171,224,187,75,95,163,75,240,140,82,89,226,193,213,77,6,209,31,205,76,169,140,146,156,160,185,29,222,127,0,189,50,110,192,224,239,109,3,26,36,167,194,212,149,170,234,138,42,33,75,153,19,129,73,40,100,208,153,80,111,150,143,91,11,90,100,112,219,246,235,198,119,23,115,80,174,86,68,21,21,203,171,178,48,210,54,132,86,5,214,192,32,164,215,154,190,182,71,28,49,164,50,43,4,72,107,155,149,168,26,107,16,215,180,67,76,56,208,84,42,36,220,118,248,89,242,133,228,82,8,206,138,92,169,156,163,3,81,33,46,103,47,48,194,242,51,146,159,81,181,164,76,51,169,41,91,96,123,215,152,206,246,205,105,80,161,185,92,20,5,79,160,173,9,166,3,189,155,230,180,49,213,198,202,38,172,109,252,236,251,33,218,112,241,60,18,83,209,154,75,102,20,169,105,145,35,41,158,186,235,236,48,152,117,42,3,79,211,127,183,111,23,179,30,6,250,118,207,189,153,25,158,251,174,27,123,236,255,202,143,113,3,137,194,58,153,207,175,46,83,86,151,254,118,40,123,125,251,117,99,182,243,132,18,247,136,252,250,189,133,76,216,131,179,166,177,225,211,147,46,175,8,156,22,231,222,7,215,164,30,113,47,14,108,254,252,250,241,247,231,111,60,211,128,252,189,13,160,89,201,153,18,69,142,100,76,109,207,125,131,56,53,189,26,213,139,130,111,207,203,157,218,66,103,239,172,3,141,233,235,57,53,42,70,240,165,71,129,224,206,184,49,121,4,193,231,63,185,236,195,182,13,182,121,41,116,185,36,60,9,141,219,32,11,113,13,83,90,221,135,101,240,126,139,183,134,150,115,146,180,252,31,125,219,167,208,253,5,232,199,238,25,196,36,225,101,57,221,76,255,0,85,168,136,227,126,3,0,0]
}

# 1. 将payload数组转换为字节对象
compressed_bytes = bytes(api_response["payload"])

# 2. Gzip解压
with gzip.GzipFile(fileobj=BytesIO(compressed_bytes), mode='rb') as f:
    decompressed_data = f.read()

# 3. 解析为二维矩阵(假设解压后是JSON格式的字符串)
matrix = json.loads(decompressed_data.decode('utf-8'))

print(matrix)

JavaScript 实现示例

Node.js 环境

const zlib = require('zlib');

// API返回的响应数据
const apiResponse = {
    "isPacked": true,
    "payload": [31,139,8,0,0,0,0,0,0,3,117,83,205,110,219,48,12,126,23,158,221,64,146,37,89,214,109,43,48,160,91,119,217,114,105,135,98,144,109,37,49,42,91,129,44,247,7,129,129,157,247,14,123,136,189,210,78,123,140,81,110,210,116,69,106,24,130,77,126,36,63,242,163,118,16,236,48,186,8,58,134,209,102,80,153,24,157,29,64,127,219,65,59,124,49,206,61,30,92,171,224,187,75,95,163,75,240,140,82,89,226,193,213,77,6,209,31,205,76,169,140,146,156,160,185,29,222,127,0,189,50,110,192,224,239,109,3,26,36,167,194,212,149,170,234,138,42,33,75,153,19,129,73,40,100,208,153,80,111,150,143,91,11,90,100,112,219,246,235,198,119,23,115,80,174,86,68,21,21,203,171,178,48,210,54,132,86,5,214,192,32,164,215,154,190,182,71,28,49,164,50,43,4,72,107,155,149,168,26,107,16,215,180,67,76,56,208,84,42,36,220,118,248,89,242,133,228,82,8,206,138,92,169,156,163,3,81,33,46,103,47,48,194,242,51,146,159,81,181,164,76,51,169,41,91,96,123,215,152,206,246,205,105,80,161,185,92,20,5,79,160,173,9,166,3,189,155,230,180,49,213,198,202,38,172,109,252,236,251,33,218,112,241,60,18,83,209,154,75,102,20,169,105,145,35,41,158,186,235,236,48,152,117,42,3,79,211,127,183,111,23,179,30,6,250,118,207,189,153,25,158,251,174,27,123,236,255,202,143,113,3,137,194,58,153,207,175,46,83,86,151,254,118,40,123,125,251,117,99,182,243,132,18,247,136,252,250,189,133,76,216,131,179,166,177,225,211,147,46,175,8,156,22,231,222,7,215,164,30,113,47,14,108,254,252,250,241,247,231,111,60,211,128,252,189,13,160,89,201,153,18,69,142,100,76,109,207,125,131,56,53,189,26,213,139,130,111,207,203,157,218,66,103,239,172,3,141,233,235,57,53,42,70,240,165,71,129,224,206,184,49,121,4,193,231,63,185,236,195,182,13,182,121,41,116,185,36,60,9,141,219,32,11,113,13,83,90,221,135,101,240,126,139,183,134,150,115,146,180,252,31,125,219,167,208,253,5,232,199,238,25,196,36,225,101,57,221,76,255,0,85,168,136,227,126,3,0,0]
};

// 1. 将payload数组转换为Buffer
const compressedBuffer = Buffer.from(apiResponse.payload);

// 2. Gzip解压
zlib.gunzip(compressedBuffer, (err, decompressedBuffer) => {
    if (err) {
        console.error('解压失败:', err);
        return;
    }
    // 3. 解析为二维矩阵(假设是JSON格式)
    const matrix = JSON.parse(decompressedBuffer.toString('utf-8'));
    console.log(matrix);
});

浏览器环境

需使用Gzip解压库(

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.28 00:08:37