来自 Json 响应的片段 -
[
{
"id": "ada2ac5d-57f1-4624-b35a-4fd34ada9e56",
"userId": "userid",
"firstName": "firstname",
"lastName": "lastname",
"dateAdded": "2018-07-06T04:19:21.57",
"dateOfChange": "2018-07-06T04:19:22.14",
"lastAction": "Updated",
},
{
"id": "2f395120-5440-4770-8a2e-16a77aa69c1e",
"userId": "userid",
"firstName": "firstname",
"lastName": "lastname",
"dateAdded": "2018-07-06T04:19:21.57",
"dateOfChange": "2018-07-06T04:19:21.99",
"lastAction": "Updated",
},
{
"id": "7aaa6b11-0f43-414b-a999-b03114392c21",
"userId": "userid",
"firstName": "firstname",
"lastName": "lastname",
"dateAdded": "2018-07-06T04:19:21.693",
"dateOfChange": "2018-07-06T04:19:21.743",
"lastAction": "Added",
},
]
=======================
我想根据 id 匹配捕获“lastAction”值。
我试过以下 -
responseContent = testStepp.getPropertyValue("response") //getting response
def jsonSlurper = new JsonSlurper()
def object = jsonSlurper.parseText(responseContent)
log.info "last action : : "
object.('$.[?(@.id=="ada2ac5d-57f1-4624-b35a-4fd34ada9e56")].lastAction')
结果 -
最后一个动作::[null,null,null,null,null,null,null,null,null,null]