Use TypeReference to specify the type of data to deserialize when using generics

Void testTypeReference() {List List = new ArrayList<>(); list.add(1); list.add(9); list.add(4); list.add(8); JSONObject jsonObj = new JSONObject(); jsonObj.put(“a”, list); System.out.println(jsonObj);

    List<String> list2 = jsonObj.getObject("a", new TypeReference<List<Integer>>(){});

    System.out.println(list2);
}
Copy the code

The original link: blog.csdn.net/zhuzj12345/…

Output: {” A “:[1,9,4,8]} [1,9,4,8]