提问人:Din 提问时间:3/2/2023 最后编辑:Din 更新时间:3/8/2023 访问量:157
null 写入 Postman 环境变量
null is written to the Postman environment variable
问:
我想从 Json 响应中获取rating_id并将其写入环境变量。但是在发送请求时,“null”值总是写入变量
json 请求:
{
"data": {
"rating_id": "{{$guid}}",
"collection_id": "7a313397-00de-49f5-bfb7-6341323ac053",
"rating": "1",
"user_comment": "test",
"status": "1",
"create_date": "2023-03-01 11:05:00+03",
"create_user": "ivanov.ii"
}
}
JSON 响应:
{
"state": "success",
"data": {
"rating_id": "67e5b082-1c35-434f-b5e1-96eaf60310ea",
"collection_id": "7a313397-00de-49f5-bfb7-6341323ac053",
"rating": "1",
"user_comment": "test",
"status": "1",
"create_date": "2023-03-01T16:51:00.087477Z",
"create_user": "ivanov.ii"
}
}
测试:
var jsonResponse = pm.response.json();
pm.environment.set(“rating_id”, jsonResponse.rating_id);
答:
0赞
Din
3/3/2023
#1
问题是因为“rating_id”在“date”里面:
var jsonrespons = pm.response.json();
pm.environment.set("rating_id", jsonrespons["data"]["rating_id"]);
评论