将多个值传递给 Postman 中的全局变量?
Pass multiple values into global variables in Postman?
如何将多个值传递给 Postman 全局变量?
示例:
"test" variable accepting values like ["a","b"]
我尝试将 ["a","b"]
添加为全局变量值并添加 运行 测试,但它抛出:
"ReferenceError | test is not defined"
JSON如下:
{
"enabled": true,
"key": "test",
"type": "text",
"value": "[\"a\",\"b\"]"
}
pm.globals.set('my_var', JSON.stringify('["a", "b"]'))
对你有用吗?我不确定你是从哪里设置的,但这应该可以完成。
从以前的请求中捕获这样的东西比手动设置它更容易。
然后您可以使用 JSON.parse(pm.globals.get('my_var'))[0]
访问您需要的值
如何将多个值传递给 Postman 全局变量?
示例:
"test" variable accepting values like ["a","b"]
我尝试将 ["a","b"]
添加为全局变量值并添加 运行 测试,但它抛出:
"ReferenceError | test is not defined"
JSON如下:
{
"enabled": true,
"key": "test",
"type": "text",
"value": "[\"a\",\"b\"]"
}
pm.globals.set('my_var', JSON.stringify('["a", "b"]'))
对你有用吗?我不确定你是从哪里设置的,但这应该可以完成。
从以前的请求中捕获这样的东西比手动设置它更容易。
然后您可以使用 JSON.parse(pm.globals.get('my_var'))[0]