pm.response.json() 和 JSON.parse(responseBody) 之间的区别

Lex*_*nrf 4 javascript json postman

之间的根本区别是什么

const json_response = pm.response.json()
Run Code Online (Sandbox Code Playgroud)

json_response = JSON.parse(responseBody)
Run Code Online (Sandbox Code Playgroud)

Dan*_*ton 5

在 Postman 沙箱上下文中,JSON.parse(responseBody)pm.response.json()正在做同样的事情。

pm.*API 并未一直存在于产品中,其引入是为了涵盖用户在访问响应正文等内容时通常会执行的许多不同操作。

JSON.parse(responseBody)以前,用户会在沙箱环境中使用来获取这些数据。

以下是 API 方法的完整列表pm.*,但当您键入时,也可以在具有自动建议功能的应用程序中看到这一点pm.

https://learning.postman.com/docs/writing-scripts/script-references/postman-sandbox-api-reference/

我个人建议您使用pm.repsonse.json()应用程序中的方法。