Nag*_*rma 18 java arrays size json jsonpath
我使用Stefan Goessner的JsonPath找到数组或列表大小时遇到问题.我使用的是json-path-2.0.0版本.
我的jsonpath表达式是$.orders.length和JSON看起来像这样:
{
"orders" : [
...
]
}Run Code Online (Sandbox Code Playgroud)
它失败了以下错误:
com.jayway.jsonpath.PathNotFoundException: Property ['length'] not found in path $['orders']
Run Code Online (Sandbox Code Playgroud)
而且我也尝试$.orders.length()了以下错误再次失败:
com.jayway.jsonpath.PathNotFoundException: Property ['length()'] not found in path $['orders']
请建议我如何使用Goessner的JsonPath表达式获取数组的长度.
[编辑]以下是我如何获得配置:
com.jayway.jsonpath.Configuration conf = com.jayway.jsonpath.Configuration.defaultConfiguration().addOptions(Option.DEFAULT_PATH_LEAF_TO_NULL);
DocumentContext documentContext = JsonPath.using(conf).parse(orderJson);
Object val = documentContext.read(jsonPathExpression);
Run Code Online (Sandbox Code Playgroud)
and*_*ler 39
似乎length()只有在 jayway json-path库的2.1.0版本中添加了对返回数组的支持.
基于一些快速测试,该$.orders.length()表达式似乎适用于版本2.1.0和版本2.2.0,所以我认为您只需升级您的依赖版本以修复您看到的错误.
| 归档时间: |
|
| 查看次数: |
26535 次 |
| 最近记录: |