[英]Jmeter json path extractor - How to Remove [ ] from extracted value
token_id="token_id":"82903430-f9b3-4f4b-9efa-ee1b991cb735"
I am extracting token_id
using json path extractor $..token_id
. 我提取
token_id
使用JSON路径抽出$..token_id
。
And then using the variable in next post request, but it's showing extra brackets in call 然后在下一个帖子请求中使用该变量,但它在调用中显示额外的括号
"token_id":["82903430-f9b3-4f4b-9efa-ee1b991cb735"]
I belive that it is caused by changes introduced in jmeter Plugins version 1.3.0 where JSONPath
extractor support of returning multiple matching values was introduced . 我相信,这是由引入的变化引起的JMeter其中插件版本1.3.0
JSONPath
提取支持返回多个匹配值的引入 。
You can work it around using one of 3 below approaches: 您可以使用以下3种方法之一来解决它:
You can change your JSONPath
Expression to 您可以将
JSONPath
表达式更改为
$..token_id[0]
So you won't have to remove brackets and quotation marks manually 因此,您不必手动删除括号和引号
I believe you have something like: 我相信你有类似的东西:
getToken=["82903430-f9b3-4f4b-9efa-ee1b991cb735"] getToken_1=82903430-f9b3-4f4b-9efa-ee1b991cb735 getToken_matchNr=1
So just using ${getToken_1}
should work like a charm 因此,使用
${getToken_1}
应该像魅力一样工作
You can use Beanshell PostProcessor to remove brackets and quotation marks. 您可以使用Beanshell PostProcessor删除括号和引号。 Add it after the
JSONPath
Extractor and put the following code into "Script"
area: 在
JSONPath
Extractor 之后添加它并将以下代码放入"Script"
区域:
String getToken = vars.get("getToken"); getToken = getToken.replaceAll("\\\\[\\"(.*?)\\"\\\\]", "$1"); vars.put("getToken",getToken);
In JSON, brackets means array of strings, numbers, booleans, objects and arrays. 在JSON中,括号表示字符串,数字,布尔值,对象和数组的数组。
"token_id" is interpreted like a string array. “token_id”被解释为字符串数组。 Example:
例:
"token_id":["82903430-f9b3-4f4b-9efa-ee1b991cb735"]
Make sure to change "token_id" to string. 确保将“token_id”更改为字符串。
Use getToken_1
as suggested by Dmitri T to remove extra brackets, because in jmeter regex uses array to store the regex response. 使用
getToken_1
由德米特里·T作为建议删除多余的括号,因为JMeter的 正则表达式使用数组存储的正则表达式的响应。
${getToken_1}
is the proper Regex to remove the []
brackets from above response. ${getToken_1}
是从上面的响应中删除[]
括号的正确正则表达式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.