json 将空值写入Postman环境变量

bzzcjhmw  于 2023-03-04  发布在  Postman
关注(0)|答案(1)|浏览(194)

我想从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"
    }
}

测试:

变量json响应=下午响应json();
pm.环境.集合(“评级标识”,jsonResponse.评级标识);

pgvzfuti

pgvzfuti1#

问题是因为“rating_id”在“date”内:
变量json响应= pm.响应.json();
pm.环境.集合(“评级标识”,jsonrespons[“数据”][“评级标识”]);

相关问题