使用GSON解析多重巢狀的物件解析
阿新 • • 發佈:2018-12-26
全物件解析json
//這裡是最外層的物件資訊
String msg = jsonObject.get("").getAsString();
String code = jsonObject.get("msg").getAsString();
Boolean success = jsonObject.get("success").getAsBoolean();
Gson gson = newGson(); JsonObject data = jsonObject.get("data").getAsJsonObject(); Set<Map.Entry<String, JsonElement>> entrySet = data.entrySet();
//遍歷 for (Map.Entry<String, JsonElement> type : entrySet) { JsonObject obj = data.getAsJsonObject(type.getKey()); Boolean successs = obj.get("success").getAsBoolean(); SaveIdDatabean cr = gson.fromJson(obj, SaveIdDatabean.class);
}