JsonDeserializer 无法反序列化对象

发布于 2024-11-06 07:08:57 字数 1611 浏览 0 评论 0原文

我已经开始在 Honeycomb 上测试应用程序,并收到以下错误消息:

com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@408424f0 failed to deserialized json object
[{"type":"location","id":1,"name":"Manukau Heights","description":null,"children":[]},{"type":"location","id":2,"name":"Manukau Central","description":null,"children":[]},{"type":"location","id":3,"name":"Manukau City","description":null,"children":[]},{"type":"location","id":4,"name":"Redoubt North","description":null,"children":[]},{"type":"location","id":5,"name":"Redoubt South","description":null,"children":[]},{"type":"location","id":6,"name":"Goodwood Heights","description":null,"children":[]},{"type":"location","id":7,"name":"Totara Heights","description":null,"children":[]},{"type":"location","id":8,"name":"Totara Park","description":null,"children":[]}]
given the type com.google.gson.ParameterizedTypeImpl@8a7527

当使用 Gson 和 fromJson

MyLocation[] locations = gson.fromJson(in, MyLocation[].class);

MyLocation 时,它看起来像这样:

private String name = "";
private String type = "";
private String id;
private List<MyLocation> children = new ArrayList<MyLocation>();
private String description = "";

我主要担心的是,这在 Honeycomb 之前的许多设备上都能完美运行。我尝试过以下方法: Nexus 1 2.3.4, HTC Hero 2.1 更新 1, 戴尔场地 2.2.2, 戴尔 Streak 7" 2.2.2, Garmin Asus 2.1 update 1

,我没有看到任何异常(并且数据导入看起来很完美)。

任何人都可以提供可能会有所不同的建议以及我如何管理它吗?

(我遇到了类似的 XML 解析方式不同的问题,但我找到了解决方法,将其转至 Honeycomb)

问候, 朱利叶斯.

I have started to test an application on Honeycomb and get the following error message:

com.google.gson.JsonParseException: The JsonDeserializer com.google.gson.DefaultTypeAdapters$CollectionTypeAdapter@408424f0 failed to deserialized json object
[{"type":"location","id":1,"name":"Manukau Heights","description":null,"children":[]},{"type":"location","id":2,"name":"Manukau Central","description":null,"children":[]},{"type":"location","id":3,"name":"Manukau City","description":null,"children":[]},{"type":"location","id":4,"name":"Redoubt North","description":null,"children":[]},{"type":"location","id":5,"name":"Redoubt South","description":null,"children":[]},{"type":"location","id":6,"name":"Goodwood Heights","description":null,"children":[]},{"type":"location","id":7,"name":"Totara Heights","description":null,"children":[]},{"type":"location","id":8,"name":"Totara Park","description":null,"children":[]}]
given the type com.google.gson.ParameterizedTypeImpl@8a7527

when using Gson and fromJson

MyLocation[] locations = gson.fromJson(in, MyLocation[].class);

MyLocation looks like this:

private String name = "";
private String type = "";
private String id;
private List<MyLocation> children = new ArrayList<MyLocation>();
private String description = "";

The main concern I have is that this works perfectly on many devices pre Honeycomb. I have tried with the following:
Nexus 1 2.3.4,
HTC Hero 2.1 update 1,
Dell Venue 2.2.2,
Dell Streak 7" 2.2.2,
Garmin Asus 2.1 update 1

and I see no Exceptions (and the data is imported seemingly perfectly).

Can anyone give advice what might be different and how I can manage it?

(I had a similar issue with XML being parsed differently but I managed a workaround for this going to Honeycomb)

Regards,
Julius.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

潦草背影 2024-11-13 07:08:57

我改用 Jackson,这个问题就消失了。所以这并不能解释原来的问题,但似乎有效。

I switched to using Jackson and this problem has gone away. So this doesn't explain the original issue, but seems to work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文