条件 jsonpath 表达式在 groovy 脚本、jmeter 中不起作用

Conditional jsonpath expressions not working in groovy script, jmeter

Conditional jsonpath expression: 
    $.[?(@.identifier == "369")]..columns.[?(@.type == "relationship")].token
import groovy.json.JsonSlurper

JsonSlurper slurper = new JsonSlurper()
Map parsedJson = slurper.parseText(prev.getResponseDataAsString())

//String idval = parsedJson.sections[1].id

//String idval = parsedJson.[?(@.identifier == "369")]..columns.[?(@.type == "relationship")].token //trail 01 -failed at .[

String idval = parsedJson./[?(@.identifier == "369")]/..columns./[?(@.type == "relationship")]/.token  //trail 02 -no such property: columns for class

log.info(""+idval);

您不能将 JSON 路径表达式与 JsonSlurper, consider either using find()/ findAll() functions on the returned collection or moving to JsonPath 一起使用

def idval = com.jayway.jsonpath.JsonPath.read(prev.getResponseDataAsString(), '?($..sections[@.identifier == "369")]..columns.[?(@.type == "relationship")]')

更多信息:Apache Groovy - Why and How You Should Use It