复杂字符串转List<JSONObject>

public static List<JSONObject> getlist(String data){
        ObjectMapper mapper = new ObjectMapper();
        JavaType javaType = getCollectionType(ArrayList.class, JSONObject.class);
        List<JSONObject> list = null;
        try {
            list = mapper.readValue(data,javaType);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return list;
    }
    public static JavaType getCollectionType(Class<?> collectionClass, Class<?>... elementClasses) {
        return new ObjectMapper().getTypeFactory().constructParametricType(collectionClass, elementClasses);
    }

 

posted @ 2018-02-07 16:16  lensener  阅读(309)  评论(0编辑  收藏  举报