基于base64的GSON的数据压缩(二)

2014-11-24 03:24:28 · 作者: · 浏览: 1
onPrimitive(base64);
}

public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
if (!(json instanceof JsonPrimitive)) {
throw new JsonParseException("The date should be a string value");
}
try {
BASE64Decoder decode = new BASE64Decoder();
byte[] base64 = decode.decodeBuffer(json.getAsString());
return base64;
} catch (IOException ex) {
}
return null;
}
}
使用这个类将byte[]通过base64进行压缩,降低JSON的数据量4倍左右。

摘自 狐狸爱上猫----JAVA LINUX SWING EXTJS AJAX专栏