如何解决Jsonpath:无法使用表达式获得所需的值
这是 JSON 示例
{
"customerId": 0,"authorizedCustomerIds": [
0
],"creativeVersionId": 0,"description": "string","version": "string","duration": 0,"frameRate": 0,"previewImage": "string","previewVideo": "string","renderScript": "string","renderScriptType": "string","elements": [
{
"id": 0,"type": "IMAGE","name": "string1","parentId": 0,"presetId": 0,"properties": [
{
"name": "string","value": {},"type": "ALPHABETIC","producesVideo": true,"renderScriptId": "string"
}
]
},{
"id": 1,"type": "TEXT","name": "string2","producesVideo": false,"renderScriptId": "string"
}
]
}
],"globalElements": [
{
"id": 0,"disabled": true
}
],"shots": [
{
"name": "string","displayOrder": 0,"startFrame": 0,"thumbnailFrame": 0,"elements": [
{
"id": 0,"disabled": true
}
]
}
],"sizes": [
{
"name": "string","main": true,"width": 0,"height": 0,"properties": [
{
"templateElementId": 0,"propertyName": "string","linked": true,"value": {}
}
]
}
]
}
我需要获取类型为 TEXT 且属性“producesVideo”为 false 的元素名称。
我试过这种方法,但没有用
$..elements[?(@.type == 'TEXT' && @.properties[?(@.producesVideo == false)])].name
那我就放心提取路径
.extract().path();
使用 find
或 findAll
条件
解决方法
使用放心的 find
和 findAll
表达式,jsonpath 应该是这样的:
.extract().path("elements.findAll{it.type == 'TEXT' && it.properties.find{it.producesVideo == false}}.name");
,
您使用的是什么 JSONPath 实现?对于该文档和 JSONPath 表达式,一些实现,例如jayway Java 和 jsoncons C++,将返回值结果
[
"string2"
]
或路径结果
[
"$['elements'][1]['name']"
]
其他实现,例如Goessner Javascript,无法用子过滤器消化过滤器表达式。 Christoph Burgmer 的 JSONPath Comparison 涵盖了该案例 here。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。