【发布时间】:2014-06-11 16:06:02
【问题描述】:
我正在尝试将 JSON 数组转换为 Java 对象,但在理解如何使用 GSON 时遇到问题。
JSON 数组如下所示:
"[
{
"category": "1",
"checks": [
{
"check": "1.1",
"penaltypoints": "1.1",
"keypoint": "1.1"
},
{
"check": "1.2",
"penaltypoints": "1.2",
"keypoint": "1.2"
}
]
},
{
"category": "2",
"checks": [
{
"check": "2.1",
"penaltypoints": "2.1",
"keypoint": "2.1"
},
{
"check": "2.2",
"penaltypoints": "2.2",
"keypoint": "2.2"
}
]
}
]"
我对应的Java类是:
class Category {
public String description;
public List<Check> checks;
}
class Check {
public String description;
public float penaltyPoints;
public KeyPoint keypoint;
}
class KeyPoint {
public String description;
}
这就是我对 GSON 的称呼:
Gson gson = new Gson();
Category categoriesArray[] = gson.fromJson(jsonString, Category[].class);
目前它正在抛出以下错误:
Expected BEGIN_OBJECT but was STRING at line 1 column 125
我是 GSON 的新手,无法理解它的工作原理。谁能帮我理解我做错了什么?
【问题讨论】: