简体   繁体   English

Jmeter json路径提取器 - 如何从提取的值中删除[]

[英]Jmeter json path extractor - How to Remove [ ] from extracted value

From 来自

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

I am extracting token_id using path extractor $..token_id . 我提取token_id使用路径抽出$..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 Plugins version 1.3.0 where JSONPath extractor support of returning multiple matching values was introduced . 我相信,这是由引入的变化引起其中插件版本1.3.0 JSONPath提取支持返回多个匹配值的引入

You can work it around using one of 3 below approaches: 您可以使用以下3种方法之一来解决它:

  1. You can change your JSONPath Expression to 您可以将JSONPath表达式更改为

     $..token_id[0] 

    So you won't have to remove brackets and quotation marks manually 因此,您不必手动删除括号和引号

  2. 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}应该像魅力一样工作

  3. 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 uses array to store the response. 使用getToken_1由德米特里·T作为建议删除多余的括号,因为 使用数组存储的的响应。

${getToken_1} is the proper Regex to remove the [] brackets from above response. ${getToken_1}是从上面的响应中删除[]括号的正确正则表达式。

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

相关问题 Jmeter json路径提取器 - 如何删除字符串 - Jmeter json path extractor - How to Remove String 我如何基于从json路径提取器提取的值传递n个请求 - How can i pass 'n' number of requests based on value extracted from json path extractor 将 Jmeter 中的 json 提取器中提取的字符串拆分为 n 组 - Split the String extracted from json extractor in Jmeter with sets of n JMETER:如何在 Json 提取器中从 CSV 文件中添加值? - JMETER: How to add value from CSV file in Json Extractor? 试图将值(从 json 路径提取器中提取)传递给下一个 http 请求 - trying to pass the value (which is extracted from json path extractor) to the next http request 如何将在JSON路径提取器中提取的变量用于场景的进一步步骤? - How to use variable extracted in JSON path extractor for further steps of scenario? 如何在jmeter的json路径提取器中连接两个json路径查询? - How to join two json path query in json path extractor of jmeter? 通过jmeter中的json路径提取器提取json值 - extracting the json value through json path extractor in jmeter Jmeter-Json数组:如何使用Json Path Extractor检查每个值是否包含字符串 - Jmeter - Json array: How to check for each value if contains a string using Json Path Extractor 如何使用jmeter的json路径提取器从json响应中获取内部变量 - How to get a intern variable from json response using jmeter's json path extractor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM