如何在空手道中为JSON数组设置动态值 [英] How to set a dynamic value for a json array in Karate

查看:106
本文介绍了如何在空手道中为JSON数组设置动态值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

i have a json file, which needs uniq values for each post request. uniqId = '55555'. for all the uniq ids i need to pass same uniqId. so far i was able to only set for only the endtoEndid. unable to set for invoiceNum and txnValue. Please help. so far i have done following:


  • eval req = { endtoEndid:,
    prgrmId : 2344,
    发票:[{ invoiceNum:}],
    currency:5.99,
    txnRefs:[{ txnId:名称, txnValue:},{ txnId:州, txnValue:伊利诺伊州}]}

  • eval req = {"endtoEndid":"", "prgrmId":"2344", "invoices": [ { "invoiceNum":""}], "currency":5.99, "txnRefs": [ { "txnId":"name", "txnValue":""},{ "txnId":"state", "txnValue":"illinois"}]}

eval req [ ''endtoEndId'] ='endtoEnd'+ uniqId。 (成功)

eval req['endtoEndId'] = 'endtoEnd' + uniqId. (successfull)

然后我尝试拆分:


  • def reqInvoices = req.invoices

  • def reqTxnRefs = req。 txnRefs [0]

  • def reqInvoices = req.invoices
  • def reqTxnRefs = req.txnRefs[0]

eval reqInvoices ['invoiceNum'] ='invoice'+ uniqId(不成功)

eval reqInvoices['invoiceNum'] = 'invoice' + uniqId (not successful)

我需要以下结果:

{ endtoEndid: endToEndIduniqId,
prgrmId: 2344,
发票: [{ invoiceNum: invoiceuniqId}],
currency:5.99,
txnRefs:[{ txnId:名称, txnValue: txnuniqId},{ txnId:州, txnValue:伊利诺伊州}]}

{"endtoEndid":"endToEndIduniqId", "prgrmId":"2344", "invoices": [ { "invoiceNum":"invoiceuniqId"}], "currency":5.99, "txnRefs": [ { "txnId":"name", "txnValue":"txnuniqId"},{ "txnId":"state", "txnValue":"illinois"}]}

谢谢

推荐答案

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

Please try the latest version or 0.9.6.RC3.

现在设置JSON变得容易得多,您不需要任何 eval set

Setting JSON is much easier now, you don't need any eval or set.

示例:

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

其中给出:

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

这篇关于如何在空手道中为JSON数组设置动态值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆