JsonDeserializer无法反序列化对象

时间:2011-05-12 06:31:13

标签: android gson json

我已经开始在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, 戴尔Venue 2.2.2, 戴尔Streak 7“2.2.2, Garmin Asus 2.1更新1

我没有看到异常(并且数据导入看似完美)。

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

(我有一个类似的问题,XML的解析方式不同,但我为Honeycomb管理了一个解决方法)

此致 朱利。

1 个答案:

答案 0 :(得分:1)

我转而使用杰克逊这个问题已经消失了。所以这并没有解释原始问题,但似乎有效。

相关问题