可以使用以下代码将JSON格式的字符串数组转换为List<List>类型:

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONUtil;

public class Example {
    public static void main(String[] args) {
        String jsonStr = "[[\"a\", \"b\", \"c\"], [\"d\", \"e\", \"f\"]]";
        JSONArray jsonArray = JSONUtil.parseArray(jsonStr);
        List<List<String>> list = new ArrayList<>();
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONArray subArray = jsonArray.getJSONArray(i);
            List<String> subList = subArray.toList(String.class);
            list.add(subList);
        }
        System.out.println(list);
    }
}

其中,使用JSONUtil.parseArray方法将JSON格式的字符串转换为JSONArray对象,然后遍历JSONArray对象,将其中的每个子数组转化为List类型,并添加到外层List中。最终输出List<List>类型的结果。

java使用hutool的JSONUtiltoListjson字符串数组转ListlistString类型

原文地址: https://www.cveoy.top/t/topic/brg6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录