首页 > 解决方案 > 如何在空手道中为 json 数组设置动态值

问题描述

我有一个 json 文件,它需要每个 post 请求的 uniq 值。uniqId = '55555'。对于所有 uniq id,我需要传递相同的 uniqId。到目前为止,我只能为 endtoEndid 设置。无法设置 invoiceNum 和 txnValue。请帮忙。到目前为止,我已经完成了以下工作:

然后我尝试拆分:

我需要以下结果:

{"endtoEndid":"endToEndIduniqId", "prgrmId":"2344", "invoices": [ { "invoiceNum":"invoiceuniqId"}], "currency":5.99, "txnRefs": [ { "txnId":"名称”,“txnValue”:“txnuniqId”},{“txnId”:“状态”,“txnValue”:“伊利诺伊州”}]}

谢谢

标签: arraysjsonkarate

解决方案


请尝试最新版本或 0.9.6.RC3。

现在设置 JSON 要容易得多,您不需要任何evalset.

例子:

* def foo = {}
* foo.bar = 'baz'
* def random = function(){ return java.lang.System.currentTimeMillis() + '' }
* foo.ban = random()
* print foo

这使:

{
  "bar": "baz",
  "ban": "1591756622099"
}

推荐阅读