1.JSON字符串
String content = "[{" +
" \"key\": \"UserRole\"," +
" \"name\": \"员工角色\"" +
"}, {" +
" \"key\": \"RolePermission\"," +
" \"name\": \"角色权限\"" +
"}]";
2.映射实体
public class PermissionContent implements Serializable { private static final long serialVersionUID = 8891095994295070691L; private String key; private String name;
}
3.使用ObjectMapper
ObjectMapper mapper = new ObjectMapper();
CollectionType listType = mapper.getTypeFactory().constructCollectionType(ArrayList.class, PermissionContent.class);
List<PermissionContent> userList = mapper.readValue(content, listType);
System.out.println(userList.get(0).getKey());