在Jmeter中使用JSR223 Groovy..我花了很多时间在JSON块中替换这个字符串
"ABC": {"seconds": 20},
使用
"ABC": {"seconds": ${myVal}}, (this way my value in seconds is variable)
我试过了
str1 = str1.replaceAll('"ABC": {"seconds": 20}', '"ABC": {"seconds": '+${myVal}+'"}"');
但这行不通。请帮帮我
发布于 2018-05-29 08:00:13
考虑一下:
def s = '''
{"ABC": {"seconds": 20},
"DEF": {"seconds": 30},
"IJK": {"seconds": 40}}
'''
def myVal = 88
def oldRegex = /"ABC": \{"seconds": 20\}/
def newStr = '"ABC": {"seconds": ' + myVal + '}'
def s2 = s.replaceAll(oldRegex, newStr);
println s2
请注意,replaceAll
的第一个参数是正则表达式,这意味着必须对{
和}
进行转义。在Groovy中转义字符时,我们通常更喜欢/\{/
(斜杠字符串)而不是"\\{"
。
https://stackoverflow.com/questions/50574355
复制相似问题