JsonPath 从 json 字符串返回 json 对象的结果不同

问题描述

我正在使用 JsonPath-2.4.0.jar 并尝试从 json 中提取对象类型值时得到不同的结果。

String json="{\r\n  \"array\": [\r\n    1,\r\n    2,\r\n    3\r\n  ],\r\n  \"boolean\": true,\r\n  \"color\": \"gold\",\r\n  \"null\": null,\r\n  \"number\": 123,\r\n  \"object\": {\r\n    \"a\": \"b\",\r\n    \"c\": \"d\"\r\n  },\r\n  \"string\": \"Hello World\",\r\n  \"test\": {\r\n    \"test2\": {\r\n      \"test3\": \"hello\"\r\n    }\r\n  },\r\n  \"test2\": {\r\n    \"test2\": {\r\n      \"test3\": \"hello\"\r\n    }\r\n  },\r\n  \"teststring\": \"{\\\"test1\\\":\\\"abc\\\"}\"\r\n}";
        
 Object str =  JsonPath.read(json,"$.test");
 System.out.println(str);

结果: {test2={test3=hello}}

为什么?如何从 JSON 中获取实际的 json 对象?

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)