8

I am currently using a code (best answer on a question) I found here everything works properly until you give it a japanese String input.

I thought the UTF-8 charset would do the trick but I am not really sure what part of the code does not allow japanese characters to be serialized.

For example if I serialize something basic like "ひらがな" it will output garbage characters.

What I am doing is something like

String serialized = serialize("ひらがな");
String deserialized = deserialize(serialized, new TypeToken<String>() {}.getType());
System.out.println(deserialized);

But I am getting a garbage deserialized.

Can someone please shed some light? Thank you.

4

1 回答 1

6

我不知道您的问题的确切答案,但我可以说我遇到了类似的问题,这是我的解决方案。也许这是对你的提示:

我只使用 GSON 进行反序列化。我不得不更改以下代码

json = gson.fromJson(new InputStreamReader(is), parseType);

json = gson.fromJson(new InputStreamReader(is,"UTF-8"), parseType);

所以问题出在我的输入流阅读器中,而不是 GSON 本身。我想知道您是否需要使用字符串阅读器进行反序列化或其他操作。对不起,我不能给你更具体的答案。

于 2014-01-10T19:44:08.663 回答