如何在空手道中将变量用作 json 键?
How can I use a variable as a json key in karate?
* def myvariable = 1
* def schema =
"""
{
myvariable : '#number',
2: '#number',
3: '#number',
4: '#number',
5: '#number',
6: '#number',
}
"""
我需要使用 'myvariable' 作为密钥。我怎样才能做到这一点?
给你:
* def schema = {}
* schema.myvariable = 1
* match schema == { myvariable: 1 }
# dynamic key name
* def name = 'myvariable'
* def schema = {}
* schema[name] = 1
* match schema == { myvariable: 1 }
* def myvariable = 1
* def schema =
"""
{
myvariable : '#number',
2: '#number',
3: '#number',
4: '#number',
5: '#number',
6: '#number',
}
"""
我需要使用 'myvariable' 作为密钥。我怎样才能做到这一点?
给你:
* def schema = {}
* schema.myvariable = 1
* match schema == { myvariable: 1 }
# dynamic key name
* def name = 'myvariable'
* def schema = {}
* schema[name] = 1
* match schema == { myvariable: 1 }