如何在空手道中json数组名称具有空格的地方找到json键值

时间:2019-01-18 10:52:11

标签: karate

我需要在json中声明一个数组元素,其中数组名称中有空格

示例json:

{
"integration": {
    "message": {
        "code": 0,
        "description": "Success"
    },
    "serviceData": {
        "TenantID": "1909627861",
        "Company Name": "anupamaCompany",
        "Sub Domain": "testadd",
        "Usage Data": [{
            "Stage": "Test",
            "Service Type": "OrchestrationIntegration",
            "Integration Name": "Add",
            "Applications List": [],
            "createdBy": "Anupama2",
            "Created Date": "2018-10-03",
            "Last ModifiedBy": "Anupama2",
            "Last Modified Date": "2019-01-10",
            "Integration Type": "Light"

        }, {
            "Stage": "Development",
            "Service Type": "OrchestrationIntegration",
            "Integration Name": "Xzxzx",
            "Applications List": [],
            "createdBy": "Anupama2",
            "Created Date": "2019-01-11",
            "Last ModifiedBy": "Anupama2",
            "Last Modified Date": "2019-01-11",
            "Integration Type": "Light"
        }]
    }
}
}

要声明的值:

integration.serviceData.["Usage Data"].Stage

当我遍历“使用数据”时,由于有空间而出错。

1 个答案:

答案 0 :(得分:1)

您使用空格访问键的方法是正确的,但是看起来您忘记了在“使用数据”中的数据,它是数组/列表类型的数据。

因此您必须通过索引或json深度扫描或许多其他选项来访问它。

这里很少,

# to get all usage data as list
* def usageData = $example.integration.serviceData.['Usage Data']
# to get all stage in usage data
* def stages = $example.integration.serviceData.['Usage Data']..Stage