0
我只是想知道,如果有人可以帮助我..使用GSON解析JSON(通过分形生成)
所以,我有我一直在使用分形来解析对象,生成一些漂亮的JSON开发的API被我正在制作的Android应用程序所使用。
的JSON输出看起来有点像这样:
{
"data": [
{
"id": 1,
"name": "John Smith",
"description": "Information about John Smith",
"games": {
"data": [
{
"name": "Batman Arkham City",
"description": "Information about Game 1"
},
{
"name": "Silent Hill",
"description": "Information about Game 2"
}
]
}
}
]
}
解析这个使用GSON,我明明要创建一个人模型,它有一个ArrayList的的的是..请注意数据关键?我如何指导Gson解析这个?我明白去除有JSON这个样子的:
{
"data": [
{
"id": 1,
"name": "John Smith",
"description": "Information about John Smith",
"games": [
{
"name": "Batman Arkham City",
"description": "Information about Game 1"
},
{
"name": "Silent Hill",
"description": "Information about Game 2"
}
]
}
]
}
我一个人的模型看起来有点像这样:
public class Person
{
public String name;
public ArrayList<Game> games;
就像我说的,去掉数据键可以让我将数据解析为Java模型,如下所示:
peopleArray = jsonObject.getJSONArray("data");
Type listType = new TypeToken<ArrayList<Person>>() {}.getType();
ArrayList<Person> result = new Gson().fromJson(peopleArray.toString(), listType);
所以基本上,有什么办法可以告诉Gson游戏数组将有一个资料重点?对不起,信息超载,希望这会有道理?
Ta