karate - 如何在空手道中获取名称中包含@的JSON元素的值
问题描述
这是我的 json 回复
{
"meta": {
"type": "event-search",
"@href": "https://<ip>:<port>/SentinelRESTServices/objects/event-search/10c21c52229bfe0545BD7802A74E10398534005056869AAA"
}
}
我想获得@href 的值。当我打印 meta.type 时,我可以获得值“事件搜索”,但同样不适用于 @href。
我试图使用 \\ (meta.\\@href) 来逃避它,但我得到了空值。
有没有办法逃避 @ 并获取值?
请帮忙!!
解决方案
当键名中有特殊字符时,请使用方括号 JS 方法提取嵌套属性。
例子:
* def response = { meta: { '@href': 'foo' } }
* match response.meta['@href'] == 'foo'
推荐阅读
- elasticsearch - 使用 JMeter 向 Elasticsearch 进行身份验证
- c# - ADAL AcquireTokenAsync 不想要父窗口
- haddock - 为什么我的 Haddock 生成的文档主页的签名部分是空的?
- reactjs - 解析文件时出现意外令牌 (8:8)
- c++ - 将 _m256i 转为 int 数组
- c# - C# - 将字符串数组转换为多维字符串数组
- r - 将斜体放入 xtable 标题
- python - Python 需要很长时间才能执行代码
- sql - 简单的 VBA 选择查询
- web-services - SSIS Web 服务脚本任务 wsdl 文件