java list t 转字符串,List<Map<String,Object>>转List<T> list map对象转list对象

上代码:

public class User {

private String name;

private int age;

//构造方法

public User(){}

//有参数构造方法

public User(String name,int age){

this.name = name;

this.age = age;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

public static void main(String[] args) {

List> listMap = new ArrayList<>();

Mapmap1 = new HashMap();

map1.put("name", "李思思");

map1.put("age", 26);

Mapmap2 = new HashMap();

map2.put("name", "宋圆圆");

map2.put("age", 25);

Mapmap3 = new HashMap();

map3.put("name", "苏小小");

map3.put("age", 25);

listMap.add(map1);

listMap.add(map2);

listMap.add(map3);

JSONArray jsonArray = new JSONArray();

jsonArray.addAll(listMap);

Listlist = jsonArray.toJavaList(User.class);

for (User user : list) {

System.out.println(user.getName()+"======"+user.getAge());

}

java list t 转字符串,List<Map<String,Object>>转List<T> list map对象转list对象_第1张图片

你可能感兴趣的:(java,list,t,转字符串)