67,513
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) {
String json = "{\n" +
" \"code\": \"1000\",\n" +
" \"success\": true,\n" +
" \"message\": \"操作成功\",\n" +
" \"data\": [\n" +
" {\n" +
" \"id\": \"p_1\",\n" +
" \"parentId\": \"0\",\n" +
" \"fullName\": \"安徽省\",\n" +
" \"shortName\": null,\n" +
" \"type\": \"0\"\n" +
" },\n" +
" {\n" +
" \"id\": \"p_2\",\n" +
" \"parentId\": \"0\",\n" +
" \"fullName\": \"北京市\",\n" +
" \"shortName\": null,\n" +
" \"type\": \"0\"\n" +
" },\n" +
" {\n" +
" \"id\": \"p_3\",\n" +
" \"parentId\": \"0\",\n" +
" \"fullName\": \"福建省\",\n" +
" \"shortName\": null,\n" +
" \"type\": \"0\"\n" +
" }]}";
JsonParser parser = new JsonParser();
JsonElement element = parser.parse(json);
JsonObject root = element.getAsJsonObject();
JsonObject f = root.get("data").getAsJsonObject().remove("id").getAsJsonObject();
DivisionDTO[] dos = new Gson().fromJson(root.get("data"), DivisionDTO[].class);