fastjson2 icon indicating copy to clipboard operation
fastjson2 copied to clipboard

JSONPath 多层结构的set

Open chcodex opened this issue 4 years ago • 6 comments

JSONObject jsonObject = new JSONObject(); JSONPath.set(jsonObject, "a/0/b", 1); System.out.println(jsonObject);

期待 {"a":[{"b":1}]},依然不符合预期

Originally posted by @wenkang-du in https://github.com/alibaba/fastjson2/issues/379#issuecomment-1147111921

chcodex avatar Jun 07 '22 01:06 chcodex

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.7-SNAPSHOT/ bug已修复,请帮用2.0.7-SNAPSHOT版本验证

wenshao avatar Jun 07 '22 20:06 wenshao

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.7-SNAPSHOT/ bug已修复,请帮用2.0.7-SNAPSHOT版本验证

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.7-SNAPSHOT/ bug已修复,请帮用2.0.7-SNAPSHOT版本验证

已用2.0.7-SNAPSHOT版本验证过未解决问题

不过 JSONPath.set(jsonObject, "a[0].b", 1); 这种写法可以

chcodex avatar Jun 08 '22 02:06 chcodex

https://github.com/alibaba/fastjson2/releases/tag/2.0.7 问题已经修复,请用新版本

wenshao avatar Jun 11 '22 20:06 wenshao

https://github.com/alibaba/fastjson2/releases/tag/2.0.7 问题已经修复,请用新版本

2.0.7 正式版貌似 JSONPath.set(jsonObject, "a/0/b", 1); 结果还是{"a":1} 而不是{"a":[{"b":1}]},还是不对啊

chcodex avatar Jun 13 '22 04:06 chcodex

a/0/b

这个不是支持的语法,不支持的,应该报错的

wenshao avatar Jun 13 '22 05:06 wenshao

因为是调用 System.out.println(JSONPath.paths(JSON.parseObject("{"a":[{"b":1}]}"))); 输出了{/a=[{"b":1}], /a/0={"b":1}, /a/0/b=1, /={"a":[{"b":1}]}} 所以使用了这种语法,并且fastjson1 也是支持的

chcodex avatar Jun 13 '22 05:06 chcodex