我做一艘船防御游戏的阵列。
我有越来越航点的阵列的一个问题。 地图包含JSON
格式(使用GSON
)如何遍历JSON对象(GSON)
{
"waypoints" : {
"ship": {
"first_type": [[0,0],[5,7],[2,8],[4,4],[10,10],[12,0],[0,12],[12,8],[8,8]]
},
"boat": {
"first_type": [[0,0],[5,7],[2,8],[4,4],[10,10],[12,0],[0,12],[12,8],[8,8]]
}
}
}
我的代码:
jse = new JsonParser().parse(in);
in.close();
map_json = jse.getAsJsonObject();
JsonObject wayPoints = map_json.getAsJsonObject("waypoints").getAsJsonObject("ship");
我写了这一个,但它不工作。
JsonArray asJsonArray = wayPoints.getAsJsonObject().getAsJsonArray();
如何可以foreach对象数组?