本文介绍了Jmeter json路径提取器-如何从提取的值中删除[]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

来自json

token_id="token_id":"82903430-f9b3-4f4b-9efa-ee1b991cb735"

我正在使用 json 提取token_id路径提取器$..token_id.

I am extracting token_id using jsonpath extractor $..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"]

推荐答案

我相信这是由 jmeter 插件版本1.3.0的问题,其中JSONPath提取器支持返回多个匹配值 .

I belive that it is caused by changes introduced in jmeterPlugins version 1.3.0 where JSONPath extractor support of returning multiple matching values was introduced.

您可以使用以下三种方法之一解决此问题:

You can work it around using one of 3 below approaches:

  1. 您可以将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

因此,仅使用${getToken_1}应该可以像灵符一样工作

So just using ${getToken_1} should work like a charm

您可以使用 Beanshell后处理器删除括号和引号.将其添加到JSONPath提取器的之后,然后将以下代码放入"Script"区域:

You can use Beanshell PostProcessor to remove brackets and quotation marks. Add it after the JSONPath Extractor and put the following code into "Script" area:

String getToken = vars.get("getToken");
getToken = getToken.replaceAll("\\[\"(.*?)\"\\]", "$1");
vars.put("getToken",getToken);

这篇关于Jmeter json路径提取器-如何从提取的值中删除[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 00:02