如何在jmeter中使用groovy代码进行关联?

2guxujil  于 2022-11-01  发布在  其他
关注(0)|答案(1)|浏览(208)
1) In my response body comes like json format.
    2) Some expected reason ,i have changed that body json to normal text using below code and working expected way          
                 import groovy.json.*
                 String js = vars.get("cAccountDetails")
                 def data = new JsonSlurper().parseText(js)
                 log.info("the value is "+ data)
                 vars.putObject('data', data) 
    3) This code meaning converted json to normal text and stored in some variable thats "data"
    4) so my response stored in "data" variable .
    5) From "data", how can i extract**specific data**using groovy code or some other code?
           import java.util.regex.*
           import java.util.regex.Matcher
           import java.util.regex.Pattern
           def matches = (data =~ '{accountDetails=\\[(.*)\\],')
           vars.putObject('matches', matches)

上述代码用于关联{“匹配”变量将存储提取的值}
1.但是上面的代码不工作,我怎么能解决这个问题?

Thanks in advance!!
xkrw2x1b

xkrw2x1b1#

我们无法帮助您,除非您共享您的cAccountDetails变量值,并指出您需要从中提取什么。
第一眼看起来,正则表达式应该有点不同,即。

def matches = (data =~ /accountDetails=[(.*)],/)

更多信息:

相关问题