ReferenceError:REVISION没有定义(ReferenceError: REVISION is not defined)
阅读JSON响应
"deviceInfo": { "SERIALNUMBER": "0815", "HW-REVISION": "42" }我遇到了标题中提到的参考错误,同时访问了“HW-REVISION”。 请在下面找到我的代码,
pm.test("To verify that deviceinfo hardware revision is given as expected", function(){ var jsonData = pm.response.json(); pm.expect(jsonData.data.device.deviceInfo.HW-REVISION).to.eql("42"); });While reading the JSON response
"deviceInfo": { "SERIALNUMBER": "0815", "HW-REVISION": "42" }I faced reference error mentioned in the title, while accessing "HW-REVISION". Please find my code below,
pm.test("To verify that deviceinfo hardware revision is given as expected", function(){ var jsonData = pm.response.json(); pm.expect(jsonData.data.device.deviceInfo.HW-REVISION).to.eql("42"); });最满意答案
HW-REVISION存在这个问题,因为它对变量名不是有效的字符。
jsonData.data.device.deviceInfo.HW-REVISION试图从jsonData.data.device.deviceInfo.HW提取REVISION
相反,您可以按如下方式访问该变量:
pm.expect(jsonData.data.device.deviceInfo['HW-REVISION']).to.eql("42");The - in HW-REVISION is the problem, since it is no valid char for a variable name.
jsonData.data.device.deviceInfo.HW-REVISION tries to extract REVISION from jsonData.data.device.deviceInfo.HW
Instead you can access the variable as following:
pm.expect(jsonData.data.device.deviceInfo['HW-REVISION']).to.eql("42");更多推荐
发布评论