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

[FEATURE]含有重复key的json转为JSONObject使得重复的key元素的部分,合并为数组形式 #263

Closed
mancong opened this issue May 16, 2022 · 4 comments
Labels
enhancement New feature or request
Milestone

Comments

@mancong
Copy link

mancong commented May 16, 2022

请描述您的需求或者改进建议

可否实现 含有重复key的json字串转化jsonObject,使得重复的key元素的部分,合并为数组形式 效果呢?

请描述你建议的实现方案

按照标准json规范来将,此类情况应当为JSONArray 格式,
但是在解析 某些已有的数据时,会存在该种情况,且也会存在数据丢失的问题。

描述您考虑过的替代方案

使用net.sf.json.JSONObject 可以实现

附加信息

@mancong mancong added the enhancement New feature or request label May 16, 2022
@wenshao
Copy link
Member

wenshao commented May 16, 2022

json规范没有规定这个吧

@mancong
Copy link
Author

mancong commented May 17, 2022

json规范没有规定这个吧

是的,所以这个 是在特殊情况下的 需求,不知道 大佬 如何 规划了😀

@wenshao
Copy link
Member

wenshao commented Jun 2, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.6-SNAPSHOT/

已经支持,请帮忙用2.0.6-SNAPSHOT版本验证,2.0.6正式版预计6月5日前发布

String str = "{\"item\":1,\"item\":2}";
JSONObject object = (JSONObject) JSON.parse(str, JSONReader.Feature.DuplicateKeyValueAsArray);

你可以这样用

@wenshao
Copy link
Member

wenshao commented Jun 4, 2022

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

@wenshao wenshao closed this as completed Jun 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants