我有以下json-
{
"issues": [{
"id": 200615,
"custom_fields": [{
"id": 166,
"name": "Severity",
"internal_name": null,
"field_format": "list",
"value": "Major"
}, {
"id": 167,
"name": "Reproducibility",
"internal_name": null,
"field_format": "list",
"value": "Always"
}, {
"id": 168,
"name": "Resolution",
"internal_name": null,
"field_format": "list",
"value": "open"
}]
}]
}
从这个json中,我想获得issues的值->custome_fields的值,其中id为167,期望值为-Always(167可以在json中的任何位置,因此不能硬编码(
你能告诉我如何实现价值吗?
jsonPath.get("issues[0].custom_fields[?(@.id == '167')].value[0]")
结果出错-
java.lang.IllegalArgumentException: Invalid JSON expression:
Script1.groovy: 1: expecting EOF, found '[' @ line 1, column 50.
Object.issues[0].custom_fields[?(@.id ==
我得到了和你一样的错误,我不知道为什么。
然而,您可以使用findAll
json路径方法来实现相同的目标,如下所示:
issues[0].custom_fields.findAll { it.id == 167 }.value[0]
打印输出:Always
$.issues[0].custom_fields[?(@.id==167)].value