如何连接其中包含双引号的字符串(JMeter)

问题描述 投票:0回答:2

我有一种情况,我需要连接两个字符串1和2。

Str1: {"CodeName":"service:batch","data":{"prId":${TestId},"filters":[{
Str2: "tallId":

看起来像:

{"CodeName":"service:batch","data":{"prId":${TestId},"filters":[{"tallId":

试过:

Str1 = Str1 + "\"tallId\":";
string jmeter concatenation beanshell
2个回答
0
投票

将以下代码放在beanshell脚本区域中:

String Str1 = vars.get("mainString");
String Str2 = "\"teamId\":";
String Str3 = Str1 + Str2;
vars.put("NewString", Str3);

enter image description here


0
投票
  1. 使用字符串连接构建JSON不是最佳选择
  2. JMeter Functions and Variables内联到Script体中是一种非常糟糕的做法
  3. 自从JMeter 3.1 it is recommended to use JSR223 Elements and Groovy language用于JMeter中的任何形式的脚本

所以我建议使用Groovy语言重新考虑你的方法,因为它有built-in JSON support,所以你应该能够从JMeter变量创建一个“好”的JSON对象,而不必担心引号,逗号等。

© www.soinside.com 2019 - 2024. All rights reserved.