-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
[BUG]JSONPath.extract抛异常 #858
Comments
String tmpJson = "{\"arr\": [{ \"key\": \"value1\" }, { \"key\": \"value2\" }]}";
String tmpPath = "$.arr[?(@.key='value1')]";
Object tmpObj = JSONPath.extract(tmpJson, tmpPath);
assertEquals("[{\"key\":\"value1\"}]", JSON.toJSONString(tmpObj)); 可以这样写 |
不建议修改用法,新老版本不兼容,而且网上的文档又没有更新,这样显得特别bug。这个是官方的文档,并没有@的用法:https://alibaba.github.io/fastjson2/jsonpath_cn |
https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.17-SNAPSHOT/ |
2.0.17-SNAPSHOT验证过$.arr[?(key='value1')]是可以了,但是$.arr[key='value1']依然不行,我不清楚哪种才是正确的写法,因为官方文档中( https://alibaba.github.io/fastjson2/jsonpath_cn ),第一列格式是有问号,第二列的示例却没有,麻烦请修改一下文档,避免误导用户 |
问题描述
JSONPath.extract解析报Exception
环境信息
重现步骤
执行以下代码
期待的正确结果
相关日志输出
以下是path="$.arr[key='value1']"的异常
Exception in thread "main" com.alibaba.fastjson2.JSONException: TODO : k
at com.alibaba.fastjson2.JSONPath$JSONPathParser.parseArrayAccess(JSONPath.java:6338)
at com.alibaba.fastjson2.JSONPath$JSONPathParser.parse(JSONPath.java:6160)
at com.alibaba.fastjson2.JSONPath.of(JSONPath.java:398)
at com.alibaba.fastjson.JSONPath.extract(JSONPath.java:30)
如果path="$.arr[?(key='value1')]"则输出以下异常
Exception in thread "main" com.alibaba.fastjson2.JSONException: jsonpath syntax error, offset 9, character k, line 1, column 10, fastjson-version 2.0.15 $.arr[?(key='value1')]
at com.alibaba.fastjson2.JSONPath$JSONPathParser.parseFilter(JSONPath.java:6839)
at com.alibaba.fastjson2.JSONPath$JSONPathParser.parseArrayAccess(JSONPath.java:6313)
at com.alibaba.fastjson2.JSONPath$JSONPathParser.parse(JSONPath.java:6160)
at com.alibaba.fastjson2.JSONPath.of(JSONPath.java:398)
at com.alibaba.fastjson.JSONPath.extract(JSONPath.java:30)
附加信息
测试过fastjson 1.2.69版本无此问题
The text was updated successfully, but these errors were encountered: