使用hutool的工具类
import cn.hutool.json.JSON;
import cn.hutool.json.JSONConfig;
import cn.hutool.json.JSONUtil;
public class Main {
public static void main(String[] args) {
String sss = "{\"1\":\"a\",\"2\":null}";
// 不显示null
JSON json = JSONUtil.parse(sss);
System.out.println(json);
// 显示null
JSONConfig config = new JSONConfig().setIgnoreNullValue(false);
JSON json1 = JSONUtil.parse(sss,config);
System.out.println(json1);
}
}

本文介绍了如何使用Hutool的JSONUtil类解析JSON字符串,展示了在忽略null值和不忽略null值两种配置下的不同输出结果。
2900

被折叠的 条评论
为什么被折叠?



