【发布时间】:2016-08-26 04:26:21
【问题描述】:
我在使用 Stefan Goessner 的 JsonPath 查找数组或列表大小时遇到问题。我使用的是 json-path-2.0.0 版本。
我的 jsonpath 表达式是 $.orders.length,而 JSON 看起来像这样:
{
"orders" : [
...
]
}
失败并出现以下错误:
com.jayway.jsonpath.PathNotFoundException: Property ['length'] not found in path $['orders']
我也尝试了$.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);
【问题讨论】:
标签: java arrays json size jsonpath