gzip解压json入参 java
时间: 2023-10-21 20:15:41 浏览: 95
您可以使用Java中的GZIPInputStream类来解压缩GZip压缩的数据。以下是一个将GZip压缩的JSON字符串解压缩为字符串的示例代码:
```java
public static String decompress(String compressedJsonString) {
String uncompressedJsonString = null;
try {
ByteArrayInputStream bis = new ByteArrayInputStream(Base64.getDecoder().decode(compressedJsonString));
GZIPInputStream gis = new GZIPInputStream(bis);
InputStreamReader reader = new InputStreamReader(gis);
BufferedReader in = new BufferedReader(reader);
StringBuffer sb = new StringBuffer();
String line;
while ((line = in.readLine()) != null) {
sb.append(line);
}
uncompressedJsonString = sb.toString();
} catch (IOException e) {
e.printStackTrace();
}
return uncompressedJsonString;
}
```
请注意,此示例假定输入的JSON字符串已经经过Base64编码。如果未经过编码,则可以跳过Base64解码步骤。
阅读全文