ReferenceError:REVISION没有定义(ReferenceError: REVISION is not defined)

编程入门 行业动态 更新时间:2024-10-25 20:20:53
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");

更多推荐

本文发布于:2023-08-04 07:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412441.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:定义   ReferenceError   REVISION   defined

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!