我想從這個鏈接解析JSON字符串獲得:https://api.guildwars2.com/v2/items/56,一切很好,直到我遇到了行:"infix_upgrade":{"attributes":[{"attribute":"Power","modifier":4},{"attribute":"Precision","modifier":3}]}
...GSON從複雜的JSON
如果我沒有得到這個錯誤:infix_upgrade
有1元attributes
在他裏面。 attributes
有2個元素和其他2個元素。這是一個2維數組嗎?
我已經試過(代碼太長髮布):
JsonObject _detailsObject = _rootObject.get("details").getAsJsonObject();
JsonObject infix_upgradeObject = _detailsObject.get("infix_upgrade").getAsJsonObject();
JsonElement _infix_upgrade_attributesElement = infix_upgradeObject.get("attributes");
JsonArray _infix_upgrade_attributesJsonArray = _infix_upgrade_attributesElement.getAsJsonArray();
的問題是,我不知道下一步該怎麼做,還試圖繼續轉化JsonArray到字符串數組是這樣的:
Type _listType = new TypeToken<List<String>>() {}.getType();
List<String> _details_infusion_slotsStringArray = new Gson().fromJson(_infix_upgrade_attributesJsonArray, _listType);
但即時得到java.lang.IllegalStateException: Expected STRING but was BEGIN_OBJECT
我的猜測來自屬性...