[英]Parsing jsonData from postman response
I have such response body:我有这样的响应机构:
{
"code": 400,
"message": "Any errors for orderId=12"
}
I need to store the orderId value from message
to the orderId
variable.我需要将
message
中的 orderId 值存储到orderId
变量中。 But so far I can only store the message
value completely:但到目前为止,我只能完全存储
message
值:
pm.test("app should return error", function () {
pm.response.to.have.status(400);
var jsonData = pm.response.json();
pm.expect(jsonData).to.have.property("message");
pm.collectionVariables.set("orderId", jsonData["message"]);
});
If there is only single =
in the message text, you can split the string and save it to the variable like:如果消息文本中只有一个
=
,您可以拆分字符串并将其保存到变量中,例如:
var orderId = jsonData.message.split('=')[1];
pm.collectionVariables.set("orderId", jorderId);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.