我做一艘船防禦遊戲的陣列。
我有越來越航點的陣列的一個問題。 地圖包含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對象數組?