如何在postman JS测试中验证以@开头的属性
How to validate the attributes which starts with @ in postman JS tests
我需要通过 POSTMAN JS 验证以下响应中“@type”属性的值 tests.but 当我尝试编写测试时出现语法错误(无效或意外的标记)
JS测试线:
var jsonData = JSON.parse(responseBody);
console.log(jsonData.ErrorResponse.Result.Error[0].@type)
回复:
{
"ErrorResponse": {
"Result": {
"Error": [
{
"@type": "ErrorDetail",
"StatusCode": "400",
}
]
}
}
}
您需要使用括号表示法 ["@type"]
才能访问该值:
var jsonData = pm.response.json();
console.log(jsonData.ErrorResponse.Result.Error[0]['@type'])
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors
我需要通过 POSTMAN JS 验证以下响应中“@type”属性的值 tests.but 当我尝试编写测试时出现语法错误(无效或意外的标记)
JS测试线:
var jsonData = JSON.parse(responseBody);
console.log(jsonData.ErrorResponse.Result.Error[0].@type)
回复:
{
"ErrorResponse": {
"Result": {
"Error": [
{
"@type": "ErrorDetail",
"StatusCode": "400",
}
]
}
}
}
您需要使用括号表示法 ["@type"]
才能访问该值:
var jsonData = pm.response.json();
console.log(jsonData.ErrorResponse.Result.Error[0]['@type'])
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors