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 not support integer key #842

Closed
qq1053831109 opened this issue Oct 14, 2022 · 10 comments
Closed

jsonpath not support integer key #842

qq1053831109 opened this issue Oct 14, 2022 · 10 comments
Labels
bug Something isn't working fixed
Milestone

Comments

@qq1053831109
Copy link

$.items[0].data.\0\

\0\ is data Object

0是data对象的键 data是个对象 不是数组

@qq1053831109 qq1053831109 added the bug Something isn't working label Oct 14, 2022
@qq1053831109
Copy link
Author

从fastjson1 升级到fastjson2 发现好多jsonpath 不兼容问题 !数字key在tostring的时候也会报错类型转换错误,貌似底层fastjson2 认为json的key只能是字符串

@qq1053831109
Copy link
Author

还有要支持宽松的 解析模式 很多json都是手写的 不想严格按照json格式来

@wenshao wenshao added this to the 2.0.16 milestone Oct 14, 2022
@wenshao
Copy link
Member

wenshao commented Oct 14, 2022

String str = "{\"items\": [{\"data\":{\"0\":\"abc\"}}]}";
Object result = JSONPath.eval(str, "$.items[0].data.0");
assertEquals("abc", result);

这个是不是你想要的?

wenshao added a commit that referenced this issue Oct 14, 2022
@qq1053831109
Copy link
Author

    String jsonPath = "$.items[0].data.0"; 

    Map data = new LinkedHashMap<>();
    JSONPath.set(data, jsonPath, "设置成功");

设置不进去 我的是fastjson-2.0.15

@wenshao wenshao added the fixed label Oct 15, 2022
@wenshao
Copy link
Member

wenshao commented Oct 15, 2022

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.16-SNAPSHOT/
问题已经修复,请用2.0.16-SNAPSHOT帮忙验证,2.0.16版本预计在10月30日前发布

@wenshao
Copy link
Member

wenshao commented Oct 22, 2022

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

@wenshao wenshao closed this as completed Oct 22, 2022
@qq1053831109
Copy link
Author

    Map data = new LinkedHashMap<>();
    JSONPath.set(data,  "$.obj.5", "设置成功");
    System.out.println(JSONObject.toJSONString(data));

会打印:
{"obj":[]}

我希望是打印 {"obj":{5:"设置成功"}} obj是对象 不是数组

我用的最新的2.0.16

@wenshao wenshao modified the milestones: 2.0.16, 2.0.17 Oct 22, 2022
@wenshao wenshao reopened this Oct 22, 2022
wenshao added a commit that referenced this issue Oct 29, 2022
@wenshao
Copy link
Member

wenshao commented Oct 30, 2022

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

@wenshao wenshao closed this as completed Oct 30, 2022
@qq1053831109
Copy link
Author

Map data = new LinkedHashMap<>();
JSONPath.set(data, "$.obj.5", "设置成功");
System.out.println(JSONObject.toJSONString(data));
会打印:
{"obj":[null,null,null,null,null,"设置成功"]}

我希望是打印 {"obj":{5:"设置成功"}} obj是对象 不是数组

我用的最新的2.0.17

@qq1053831109
Copy link
Author

以前的fastjson1 就是支持数字key的 或者说是字符串为数字的 如key 为"12345"

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

No branches or pull requests

2 participants