Postman - 无法从属性键中具有`:`的对象获取值

问题描述 投票:3回答:1

我正在努力从属性密钥名称中包含:的对象中获取价值。

这就是我的Response Body的样子:

{
    "links": {
        "content": {
            "href": "http://*********",
            "templated": false,
            "type": "application/hal+json"
        },
        "test:search": [
            {
                "title": "Some title",
                "href": "http://*************",
                "type": "application/hal+json"
            }
        ]
    }
}

当我试图从href获得test:search值时,Postman给了我一个错误:

“失踪”;“在声明之前”。

postman
1个回答
1
投票

如果将其添加到Tests选项卡,这应该有效:

_.each(pm.response.json().links['test:search'], (item) => {
    console.log(item.href)
    pm.environment.set('href', item.href)
})

Test Request

如果您使用它来引用属性pm.response.json().links.test:search,则无法设置变量。

Failed Request

© www.soinside.com 2019 - 2024. All rights reserved.