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设置的值与预期不符 #431

Closed
microver opened this issue Jun 7, 2022 · 3 comments
Closed

JSONPath.set设置的值与预期不符 #431

microver opened this issue Jun 7, 2022 · 3 comments
Labels
bug Something isn't working jsonpath question Further information is requested
Milestone

Comments

@microver
Copy link

microver commented Jun 7, 2022

请描述您的问题

询问有关本项目的使用和其他方面的相关问题。

                String jsonStr="{\"aaa\":\"a111\",\"bbb\":\"b11111\"}";
		JSONObject jsonObject=JsonUtil.toJsonObject(jsonStr);
		String valueStr="{\"ccc\":\"c111\",\"ddd\":\"d11111\"}";
		JSONObject value=JsonUtil.toJsonObject(valueStr);
		
		JSONPath.set(jsonObject,"$.aaa", value);
		System.out.println(jsonObject);

期待结果:{"aaa":{"ccc":"c111","ddd":"d11111"},"bbb":"b11111"}
在fastjson-1.2.7x以上版本时,结果正确
但在fastjosn-2.0.6版本下,结果如下:
{"aaa":["a111",{"ccc":"c111","ddd":"d11111"}],"bbb":"b11111"}
aaa节点原值a111仍存在,我想把新值valueStr的值完全替换原来的值,该怎么做?

@microver microver added the question Further information is requested label Jun 7, 2022
@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

@microver
Copy link
Author

microver commented Jun 8, 2022

已验证,达到预期,非常感谢!

@microver microver closed this as completed Jun 8, 2022
@wenshao
Copy link
Member

wenshao commented Jun 11, 2022

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

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 question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants