We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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处理列表数据的时候,发现当列表无数据的时候,使用$.array[*].key会报如下错误,而使用$.array[0].key(任意下标数字)都能正常返回[]。
$.array[*].key
$.array[0].key
[]
Exception in thread "main" com.alibaba.fastjson2.JSONException: TODO at com.alibaba.fastjson2.JSONPathSegment$AllSegment.accept(JSONPathSegment.java:1291) at com.alibaba.fastjson2.JSONPathMulti.extract(JSONPathMulti.java:398) at com.alibaba.fastjson2.JSONPath.extract(JSONPath.java:62)
请填写以下信息:
运行如下代码即可复现:
@Test public void test_jsonpath_array() { String json = "{ \"array\": null }"; System.out.println(JSONPath.extract(json, "$.array[0].key", JSONPath.Feature.KeepNullValue, JSONPath.Feature.AlwaysReturnList)); System.out.println(JSONPath.extract(json, "$.array[*].key", JSONPath.Feature.KeepNullValue, JSONPath.Feature.AlwaysReturnList)); }
当列表数据为null或[]时,使用*和数字的逻辑能保持一致,返回null或者[]。
null
The text was updated successfully, but these errors were encountered:
在JSON中,列表数据有值的情况,就无上述问题。
@Test public void test_jsonpath_array() { String json = "{ \"array\": [{\"key\":1}, {\"key\":null}, {\"key\":3}] }"; System.out.println(JSONPath.extract(json, "$.array[*].key", JSONPath.Feature.KeepNullValue, JSONPath.Feature.AlwaysReturnList)); }
Sorry, something went wrong.
fix remove TODO exception for issue #3192
99b8ef8
f3037a4
No branches or pull requests
问题描述
在使用JSONPath处理列表数据的时候,发现当列表无数据的时候,使用
$.array[*].key
会报如下错误,而使用$.array[0].key
(任意下标数字)都能正常返回[]
。环境信息
请填写以下信息:
重现步骤
运行如下代码即可复现:
期待的正确结果
当列表数据为
null
或[]
时,使用*和数字的逻辑能保持一致,返回null
或者[]
。The text was updated successfully, but these errors were encountered: