您可以使用此适配器在base64中序列化和反序列化字节数组。这是内容。
public static final Gson customGson = new GsonBuilder().registerTypeHierarchyAdapter(byte[].class, new ByteArrayTobase64TypeAdapter()).create(); // Using Android's base64 libraries. This can be replaced with any base64 library. private static class ByteArrayTobase64TypeAdapter implements JsonSerializer<byte[]>, JsonDeserializer<byte[]> { public byte[] deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { return base64.depre(json.getAsString(), base64.NO_WRAP); } public JsonElement serialize(byte[] src, Type typeOfSrc, JsonSerializationContext context) { return new JsonPrimitive(base64.enpreToString(src, base64.NO_WRAP)); } }归功于作者Ori
Peleg。


![使用GSON在字符串和字节[]之间转换JSON 使用GSON在字符串和字节[]之间转换JSON](http://www.mshxw.com/aiimages/31/364222.png)
