邮递员:我可以将 JSON 对象保存到环境变量中,以便将其链接到另一个请求中吗?邮递员、将其、环境变量、对象

2023-09-08 08:48:16 作者:三寸雪

我尝试使用 postman.setEnvironmentVariable() 方法,在该方法中我可以设置简单的数字和字符串值.我的问题是当我尝试保存一个对象时,它保存为 [object Object].我想知道是否可以保存 JSON 对象,以便在另一个请求中使用它.

I tried using the postman.setEnvironmentVariable() method in which I can set simple numbers and string values. My question is when I tried saving an object, it saves as [object Object]. I want to know if it is possible to save a JSON object so I can use it in another Request.

推荐答案

你应该在设置环境变量之前使用JSON.stringify().

You should use JSON.stringify() before setting it to environment variable.

然后在下一个请求中调用它后,使用 JSON.parse() 重新创建对象.

Then after you call it in next request, use JSON.parse() to recreate the object.

希望对你有帮助.