简体   繁体   English

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

[英]Conditional jsonpath expressions not working in groovy script, jmeter

Conditional jsonpath expression: 
    $.[?(@.identifier == "369")]..columns.[?(@.type == "relationship")].token
  • Problem 01: groovy script in jsr233 post processor not parsing the jsonpath expression.问题 01:jsr233 后处理器中的 groovy 脚本没有解析 jsonpath 表达式。
  • Problem 02: I need to loop identifier value in groovy or beanshell and fetch multiple array.问题 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);

You cannot use JSON Path expressions with the JsonSlurper , consider either using find() / findAll() functions on the returned collection or moving to JsonPath instead您不能将 JSON Path 表达式与JsonSlurper 一起使用,请考虑在返回的集合上使用find() / findAll()函数或改为使用JsonPath

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

More information: Apache Groovy - Why and How You Should Use It更多信息: Apache Groovy - 为什么以及如何使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM