PHP에서 처음 압축 된 Java의 json 객체의 압축을 푸는 중입니다. 여기가 PHP로 압축됩니다 방법은 다음과 같습니다Java에서 PHP의 gzcompress 압축 해제
function zip_json_encode(&$arr) {
$uncompressed = json_encode($arr);
return pack('L', strlen($uncompressed)).gzcompress($uncompressed);
}
와 (다시 PHP에서) 디코딩 : 자바하여 DB에서 MySQL을 투입됩니다 지금이 당겨해야
function unzip_json_decode(&$data) {
$uncompressed = @gzuncompress(substr($data,4));
return json_decode($uncompressed, $array_instead_of_object);
}
. 우리는이 같은 ResultSet
에서 잡아 당깁니다 :
String field = rs.getString("field");
나는 다음 압축을 해제하는 방법에 해당 문자열을 전달합니다. 이것은 그것이 붕괴되는 곳입니다.
private String decompressHistory(String historyString) throws SQLException {
StringBuffer buffer = new StringBuffer();
try {
byte[] historyBytes = historyString.substring(4).getBytes();
ByteArrayInputStream bin = new ByteArrayInputStream(historyBytes);
InflaterInputStream in = new InflaterInputStream(bin, new Inflater(true));
int len;
byte[] buf = new byte[1024];
while ((len = in.read(buf)) != -1) {
// buf should be decoded, right?
}
} catch (IOException e) {
e.getStackTrace();
}
return buffer.toString();
}
여기에 무슨 문제가 있는지 잘 모르겠지만 어떤 포인터라도 감사 할 것입니다.