我正在尝试创建一个json表达式路径,它在引用{" id ":" 00000000000000000000000004640254 "}时返回id。我已经尝试过
$.[?(@.Relationship[?(@.Ref.id=='00000000000000000000000004640254')])].id但是它不返回数据
Json消息是
[
{
"id": "234567890234567890",
"Relationship": [
{
"type": "Indirect",
"Ref": {"id": "00000000000000000000000004640253_01"}
},
{
"type": "Direct",
"Ref": {"id": "00000000000000000000000004640254"}
}
],
"Specification": {"id": "Gold123AS"}
},
{
"id": "234567890234567891",
"Relationship": [
{
"type": "Indirect",
"Ref": {"id": "00000000000000000000000004640253_02"}
},
{
"type": "Direct",
"Ref": {"id": "00000000000000000000000004640253"}
}
],
"Specification": {"id": "Gold123AS"}
}
]如果有人能帮我,谢谢
发布于 2020-05-18 22:52:30
我不认为使用JSON Extractor可以做到这一点,因为返回父节点是not implemented by underlying JsonPath library
换成JSR223 PostProcessor和Groovy语言,相关代码应该是这样的:
def json = new groovy.json.JsonSlurper().parse(prev.getResponseData())
0.upto(json.size() -1 , { idx ->
if (json.get(idx).Relationship.find { it.Ref.id.equals('00000000000000000000000004640254') } != null) {
vars.put('id', json.get(idx).id as String)
return
}
})更多信息:
https://stackoverflow.com/questions/61859684
复制相似问题