在空手道DSL中修整JSONArray中的零 [英] Trimming zeros in JSONArray in Karate DSL

查看:67
本文介绍了在空手道DSL中修整JSONArray中的零的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用JSONArray接收带有前导零的JSON响应.例如,registrationnumber = ["0000012345", "0000001234", "000123456"] 我想删除这些零并与另一个得到registrationNumber =["12345", "1234", "123456"]

I am getting a JSON response with JSONArray having leading zeros. Example, registrationnumber = ["0000012345", "0000001234", "000123456"] I want to remove these zeros and compare with another json response where I get the registrationNumber =["12345", "1234", "123456"]

我正在尝试使用空手道dsl中的自动化功能来执行此操作. 有人可以帮忙吗?

I am trying to do this with my automation in karate-dsl. Can someone help?

谢谢.

推荐答案

要转换为数字,只需乘以1.您应该阅读以下文档: https://github.com/intuit/karate#type-conversion

To convert to a number just multiply by 1. You should read the docs: https://github.com/intuit/karate#type-conversion

* def data = ["0000012345", "0000001234", "000123456"]
* def nums = karate.map(data, function(x){ return parseInt(x) })
* match nums == [12345, 1234, 123456]

这篇关于在空手道DSL中修整JSONArray中的零的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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