flutter에서 gzip으로 인코딩 된 데이터로 json 응답을 해독하는 방법은 무엇입니까?
Jan 15 2021
Json 응답에는 실제 프로세스를 얻기 위해 해독해야하는 암호화 된 객체가 있습니다. Android에서 GZip이 사용되었습니다. 어떻게 이것을 달성 할 수 있습니까? 샘플 Json은 아래에 언급 된대로입니다. 어떤 도움도 정말 감사합니다.
{
"Data": "1.´ABCD´1150275,11028´01-Jan-2021´8,000.00´",
"Data": [
{
"Element": "8iMAAB+LCAAAAAAABADt1T8zBxwHgkefKcGh98Zcdz8FSqj9DMzK4d+L0Nj1tveNR2w6M8rRs3PJWBFDy"
},
{
"Element": "B1AV4bGp6JzQJI8ChnxzixrlT8vKnYHPwRM8zykKVn2gkceAFdxMwU0to"
}
],
"Status": 1,
"Msg": "Success",
"APIVersion": "1.4"
}
기본적으로 Gzip 문자열을 해독하는 방법. 동일한 프로세스가 android에서 수행되었지만 flutter Android Java 코드가 새로 추가되었습니다. 난 설레게 그런 걸 이루고 싶어
public static String decompress(String zipText) throws IOException {
byte[] compressed = Base64.decode(zipText, Base64.DEFAULT);
if (compressed.length > 4) {
GZIPInputStream gzipInputStream = new GZIPInputStream(new ByteArrayInputStream(compressed, 4,compressed.length - 4));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
for (int value = 0; value != -1; ) {
value = gzipInputStream.read();
if (value != -1) {
baos.write(value);
}
}
gzipInputStream.close();
baos.close();
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
} else {
return "";
}
}
내가 시도한 길은
List<int> data = utf8.encode(zipText);
var deCompressedString = GZipDecoder().decodeBytes(data);
print(deCompressedString);
예외를 던지는
Unhandled Exception: FormatException: Invalid GZip Signature
답변
1 ch271828n Jan 15 2021 at 21:55
압축 해독 : Flutter에서 Gzip Http 응답을 디코딩하는 방법은 무엇입니까?
편집하다
이렇게 압축 해제
String decompress(String zipText) {
final List<int> compressed = base64Decode(zipText);
if (compressed.length > 4) {
Uint8List uint8list = GZipDecoder().decodeBytes(compressed.sublist(4, compressed.length - 4));
// print( String.fromCharCodes(uint8list));
return String.fromCharCodes(uint8list);
} else {
return "";
}
}