关于json的解析

 /*解析成list*/
    public static  java.util.List jsonToList(String source, Class<T[]> clazz) {
        Gson gson = new Gson();
        T[] array =  gson.fromJson(source, clazz);
        return Arrays.asList(array);
    }

    /*解析成map*/
    public static  Map jsonToMap(String source) {
        Gson gson = new Gson();
        Type type = new TypeToken>(){}.getType();
        Map obj = gson.fromJson(source, type);
        return obj;
    }

你可能感兴趣的:(成长之路)