【发布时间】:2019-10-02 09:45:53
【问题描述】:
我有一个 JSON 请求有效负载,我需要在其中传递 2 个值: value-1- 这是一个 10 位的随机数,例如:8000000000 value-2- 这是一个递增的数字,但只有子字符串,其中仅包含 value-1- 的递增数字的最后 4 位,即如果我将 80000000000(这是我的 value-1)增加 1000,我将得到 8000001000,所以在值 2 中,我只想显示最后 4 位数字,即 1000
我使用以下代码为 value-1 生成了随机字符串-
Generex generex = new Generex(regex); //where regex is 8605005[0-9]{3}
String randomString = generex.random();
System.out.println("This is the Random number->" + randomString);
现在我正在使用以下代码将字符串解析为整数:
int startnumbervalue;
try {
startnumbervalue = Integer.parseInt(randomString);
} catch (NumberFormatException nfe) {
nfe.printStackTrace();
}
System.out.println("This is the start number->"+startnumbervalue);
}
它在初始化变量时给出了一个错误,对于 startnumbervalue,但是当我分配 int startnumbervalue = randomstring 时 - 它给出了一个错误,指出将 startnumbervalue 的类型更改为 String。
另外,在我的方法中,我有 4 个参数:
`String regex` // to pass the value to get the random number- here i am passing- 8605005[0-9]{3} `String key` // to store the random value generated - this is my value-1 `String counter` // to get the stop range `String endrange` // the counter and the value 1 needs to be added to get the end range and subsequently i need to substring this to get only the last 4 digits.
【问题讨论】:
标签: java json cucumber httpclient