Java Hutool JSONUtil.toList 将 JSONArray 转换为 List<Map<String, Object>>
可以使用以下代码实现:
import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import java.util.List;
import java.util.Map;
public class Example {
public static void main(String[] args) {
String jsonStr = '[{"name":"张三","age":20},{"name":"李四","age":30}]';
JSONArray jsonArray = JSONUtil.parseArray(jsonStr);
List<Map<String, Object>> list = JSONUtil.toList(jsonArray, Map.class);
System.out.println(list);
}
}
这段代码首先将 JSON 字符串转为 JSONArray 对象,然后使用 JSONUtil.toList 方法将 JSONArray 转为 List<Map<String, Object>>,最后输出结果。
原文地址: https://www.cveoy.top/t/topic/mVy0 著作权归作者所有。请勿转载和采集!