Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSONPath 多层结构的set #424

Closed
Vinke2 opened this issue Jun 7, 2022 · 6 comments
Closed

JSONPath 多层结构的set #424

Vinke2 opened this issue Jun 7, 2022 · 6 comments
Labels
bug Something isn't working jsonpath
Milestone

Comments

@Vinke2
Copy link

Vinke2 commented Jun 7, 2022

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

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

Originally posted by @Wenkang-Du in #379 (comment)

@wenshao wenshao added this to the 2.0.7 milestone Jun 7, 2022
@wenshao wenshao added bug Something isn't working jsonpath labels Jun 7, 2022
@wenshao
Copy link
Member

wenshao commented Jun 7, 2022

@Vinke2
Copy link
Author

Vinke2 commented Jun 8, 2022

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); 这种写法可以

@wenshao
Copy link
Member

wenshao commented Jun 11, 2022

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

@wenshao wenshao closed this as completed Jun 11, 2022
@Vinke2
Copy link
Author

Vinke2 commented Jun 13, 2022

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}]},还是不对啊

@wenshao
Copy link
Member

wenshao commented Jun 13, 2022

a/0/b

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

@Vinke2
Copy link
Author

Vinke2 commented Jun 13, 2022

因为是调用 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 也是支持的

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working jsonpath
Projects
None yet
Development

No branches or pull requests

2 participants