【发布时间】:2010-10-17 00:50:14
【问题描述】:
我不知道如何使用 Gson 反序列化 JSON 对象内的数组。我试图反序列化的 json 对象如下所示:
{"item0":3,
"item1":1,
"item2":3,
"array":[
{"arrayItem1":321779321,
"arrayItem2":"asdfafd",
"arrayItem3":"asasdfadf"}]}
我设法构建了一个如下所示的类:
public class Watchlist {
private int itemn0;
private int itemn1;
private int itemn2;
private Object array;
}
但是当 gson 尝试反序列化数组时会抛出异常:
com.google.gson.JsonParseException: Type information is unavailable, and the target object is not a primitive: <my gson array>
谁能告诉我如何反序列化这个?
【问题讨论】:
-
你能告诉我们你抛出这个异常的代码吗?
-
抛出异常的代码只是一个fromJson调用Watchlist watchlist = gson.fromJson(jsonResponse, Watchlist.class);