空手道 DSL 中 JSON 响应的数学运算

问题描述 投票:0回答:1

从下面的回复中,我如何动态计算总费率?

[ { "name": "所得税", “率”:20 }, { “名称”:“销售税”, “率”:8 }, { "name": "房产税", “率”:2 }, { "name": "企业税", “率”:15 }, { “名称”:“消费税”, “率”:5 } ]

我已尝试添加每个费率值,但我正在寻找明智的答案?

api testing automated-tests karate
1个回答
0
投票

给你:

* def total = 0    
* def response = [ { "name": "Income Tax", "rate": 20 }, { "name": "Sales Tax", "rate": 8 }, { "name": "Property Tax", "rate": 2 }, { "name": "Corporate Tax", "rate": 15 }, { "name": "Excise Tax", "rate": 5 } ]
* response.forEach(x => total = total + x.rate)
* print total
© www.soinside.com 2019 - 2024. All rights reserved.