I got response from HTTP server as a string containing values separated by commas. I am separating those values at the client side by using comma as delimiter. But I need to convert it into integer in order to use it in my function. I used Integer.parseInt, but it is not converting.Can anyone please help.
我从HTTP服务器得到的响应是一个包含以逗号分隔的值的字符串。我使用逗号作为分隔符在客户端分隔这些值。但是我需要将它转换为整数才能在我的函数中使用它。我使用了Integer.parseInt,但它没有转换。任何人都可以帮忙。
This is the code which gets response from httpserver
这是从httpserver获取响应的代码
HttpResponse response = client.execute(post);
String responseStr = EntityUtils.toString(response.getEntity());
System.out.println("Response is " + responseStr);
separated = responseStr.split(",");
int[] numbers = new int[separated.length];
for(int i = 0;i < separated.length;i++)
numbers[i] = Integer.parseInt(separated[i]);
System.out.println(separated[0] + "and " + separated[1] + "and " + separated[2]);
the output which I am getting is :
我得到的输出是:
04-23 18:07:32.898: I/System.out(31596): Response is 1,1,15876.0
04-23 18:07:32.898:I / System.out(31596):响应是1,1,15876.0
04-23 18:07:33.867: I/System.out(31596): Response is 1,0,15876.0
04-23 18:07:33.867:I / System.out(31596):响应是1,0,15876.0
04-23 18:07:34.773: I/System.out(31596): Response is 1,0,15876.0
04-23 18:07:34.773:I / System.out(31596):响应是1,0,15876.0
04-23 18:07:35.765: I/System.out(31596): Response is 3,1,5929.0
04-23 18:07:35.765:I / System.out(31596):响应是3,1,5929.0
04-23 18:07:36.820: I/System.out(31596): Response is 3,1,5625.0
04-23 18:07:36.820:I / System.out(31596):响应是3,1,5625.0
The second sysout is not working. any help is really appreciable.
第二个sysout无法正常工作。任何帮助都是值得的。
1 个解决方案
#1
1
15876.0 is not an integer. You should have received a NumberFormatException.
15876.0不是整数。您应该已收到NumberFormatException。
You could use numbers[i] = (int)Float.parseFloat(separated[i]);
if you just need the integer part.
如果你只需要整数部分。
#1
1
15876.0 is not an integer. You should have received a NumberFormatException.
15876.0不是整数。您应该已收到NumberFormatException。
You could use numbers[i] = (int)Float.parseFloat(separated[i]);
if you just need the integer part.
如果你只需要整数部分。