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

标签 dictionary groovy jmeter conditional-statements jsonpath

Conditional jsonpath expression: 
    $.[?(@.identifier == "369")]..columns.[?(@.type == "relationship")].token
  • 问题 01:jsr233 后处理器中的 groovy 脚本不解析 jsonpath 表达式。
  • 问题 02:我需要在 groovy 或 beanshell 中循环标识符值并获取多个数组。
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 一起使用, 考虑使用 find()/findAll()在返回的集合上运行或移动到 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

关于dictionary - 条件 jsonpath 表达式在 groovy 脚本、jmeter 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57134005/

相关文章:

groovy - Groovy 中闭包的安全导航操作符是什么样的?

eclipse - Eclipse 无法解析 Groovy Grape 导入

file-io - 使用 Groovy 从 Jenkins 主节点访问从节点上的文件

Java Selenium 代码中的 java.net.MalformedURLException

jmeter - JVM 应该已经退出但没有

ios - 字符串到字典的转换总是有 Nil 值

python - 将带有 **kwargs 错误的值线程化并传递给 TypeError

POST请求正文中的Jmeter变量并在发送请求之前更改它

Objective-C 字典作为属性/方法访问

android - 室内自定义 map 应用