Jmeter数组变量转换为字符串变量以作为参数传递

von4xj4u  于 2022-11-09  发布在  其他
关注(0)|答案(1)|浏览(280)
{
      "data": {
        "companyIds": [
          5956,
          54841
        ],
        "userEmail": "abc@xyz.com",
        "contactId": 183334,
        "types": [
          1974,
          1975,
          1931,
          1932
        ],
        "boards": [
          168,
          169,
          175,
          180
          ]
         },
      "succeeded": true,
      "errors": null,
      "message": "Configuration fetched successfully",
      "statusCode": 200
    }

以上是API的json响应,我已经使用JsonExtractor在Jmeter中提取了变量,如下所示-(调试采样器结果)boardIDs_1=[168,169,175,180] boardIDs_ALL=[168,169,175,180] boardIDs_matchNr=1
我想将变量转换为类似于(168,169,175,180)格式
因为我需要将它作为参数传递给下一个API,如- Parameters。condition=board_id in(168,169,175,180)和closedFlag = false
如何在jmeter中实现?有人能帮助如何将数组[168,169,175,180]转换为字符串变量(168,169,175,180)吗?

holgip5t

holgip5t1#

将JSR 223 Postprocessor添加到请求中,并将下面的代码添加到'Script'区域。您将得到boards_INDIVIDUAL“168,169,175,180”。

def rv = new StringBuilder()

1.upto(vars.get('boards_matchNr') as int, {
    rv.append('"').append(vars.get('boards_' + it)).append('"')
    if (it as String != vars.get('boards_matchNr')) {
        rv.append(',')
    }
})

vars.put("boards_INDIVIDUAL", rv.toString())

相关问题