简体   繁体   English

如何在空手道中将变量用作 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',
}
"""

I need to use 'myvariable' as a key.我需要使用“myvariable”作为键。 How can I do this?我怎样才能做到这一点?

Here you go:这里是 go:

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

# dynamic key name
* def name = 'myvariable'
* def schema = {}
* schema[name] = 1
* match schema == { myvariable: 1 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM