JacksonUtilTest

public class JacksonUtilTest { public static void main(String\[\] args) { // 你的原始 JSON 字符串 String jsonStr = "{" + " \"clsAttrs\": " + " {" + " \\"productionCatlogLevel\\": {" + " \\"name\\": \\"3333333\\"," + " \\"brandInternationalName\\": \\"2222\\"," + " \\"states\\": {" + " \\"code\\": \\"停用\\"," + " \\"cnName\\": \\"停用\\"" + " }" + " }" + " }" + " " + "}"; // 示例1:解析 JsonNode 并获取 name(你的核心需求) JsonNode jsonNode = JacksonUtil.toJsonNode(jsonStr); String name = JacksonUtil.getStringValue(jsonNode, "clsAttrs0.productionCatlogLevel.name"); System.out.println("获取的name值:" + name); // 输出:3333333 // 示例2:获取嵌套的 states.cnName String cnName = JacksonUtil.getStringValue(jsonNode, "clsAttrs0.productionCatlogLevel.states.cnName"); System.out.println("获取的cnName值:" + cnName); // 输出:停用 // 示例3:对象转 JSON(格式化输出) User user = new User("张三", 25); String userJson = JacksonUtil.toJson(user, true); System.out.println("对象转JSON:\n" + userJson); // 示例4:JSON 转复杂类型(List<Map>) String listJson = "{\\"name\\":\\"李四\\",\\"age\\":30},{\\"name\\":\\"王五\\",\\"age\\":35}"; List<Map<String, Object>> list = JacksonUtil.fromJson(listJson, new TypeReference<List<Map<String, Object>>>() {}); System.out.println("JSON转List:" + list); } // 测试用实体类 static class User { private String name; private Integer age; public User(String name, Integer age) { this.name = name; this.age = age; } // 省略 getter/setter(Jackson 序列化需要) public String getName() { return name; } public void setName(String name) { this.name = name; } public Integer getAge() { return age; } public void setAge(Integer age) { this.age = age; } } }

相关推荐
CCPC不拿奖不改名2 小时前
大模型推理架构与开源生态知识整理
数据库·windows·python·架构·langchain·开源·github
王维同学4 小时前
[自学][Windows C++]RunOnceEx 注册表分组键的安全遍历
c++·windows·安全·开源
Geoking.8 小时前
JSON vs JSONL:从数据格式到 AI Agent 的工程实践
人工智能·深度学习·json
imatt9 小时前
Qt Creator 在Windows下编译信息乱码
windows·qt
就不掉头发9 小时前
计算机的虚拟内存
linux·服务器·windows
春风霓裳12 小时前
window设置永不更新
windows
ID_1800790547312 小时前
京东商品详情API能力解析与标准化应用方案(含JSON返回示例)
json
luyun02020213 小时前
专防未成年,吾爱出品
网络·windows·figma
love530love1 天前
【笔记】AutoClaw NSIS 安装器卡死、进程杀不掉、目录删不了?我是这么解决的
人工智能·windows·笔记·agent
大模型码小白1 天前
JAVA 集合框架进阶:List 与 Set 的深度解析与实战
java·开发语言·人工智能·windows·语言模型·list·ai编程