如何在空手道中使用变量作为json键?

问题描述 投票:1回答:1
* def myvariable = 1 
* def schema =
"""
{
  myvariable : '#number',
  2: '#number',
  3: '#number',
  4: '#number',
  5: '#number',
  6: '#number',
}
"""

我需要使用“ myvariable”作为键。我怎样才能做到这一点?

json bdd karate
1个回答
0
投票

您在这里:

* def schema = {}
* schema.myvariable = 1
* match schema == { myvariable: 1 }

# dynamic key name
* def name = 'myvariable'
* def schema = {}
* schema[name] = 1
* match schema == { myvariable: 1 }
© www.soinside.com 2019 - 2024. All rights reserved.