我正在使用 Ksoap2 从 Android 调用 Web 服务。我构建了请求,但 .call() 方法抛出以下异常:
07-22 11:12:57.718: W/System.err(9582): java.lang.NumberFormatException: Invalid int: "][2"
07-22 11:12:57.728: W/System.err(9582): at java.lang.Integer.invalidInt(Integer.java:138)
07-22 11:12:57.728: W/System.err(9582): at java.lang.Integer.parse(Integer.java:375)
07-22 11:12:57.738: W/System.err(9582): at java.lang.Integer.parseInt(Integer.java:366)
07-22 11:12:57.738: W/System.err(9582): at java.lang.Integer.parseInt(Integer.java:332)
07-22 11:12:57.738: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.getIndex(SoapSerializationEnvelope.java:287)
07-22 11:12:57.748: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.readVector(SoapSerializationEnvelope.java:304)
07-22 11:12:57.758: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(SoapSerializationEnvelope.java:446)
07-22 11:12:57.758: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:387)
07-22 11:12:57.768: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
07-22 11:12:57.768: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
07-22 11:12:57.788: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.readUnknown(SoapSerializationEnvelope.java:273)
07-22 11:12:57.788: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:389)
07-22 11:12:57.798: W/System.err(9582): at org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:151)
07-22 11:12:57.798: W/System.err(9582): at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
07-22 11:12:57.798: W/System.err(9582): at org.ksoap2.transport.Transport.parseResponse(Transport.java:118)
07-22 11:12:57.808: W/System.err(9582): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:253)
07-22 11:12:57.808: W/System.err(9582): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
07-22 11:12:57.808: W/System.err(9582): at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)
如果我将完全相同的请求放入 SoapUI,则调用有效。
即使使用 KSoap2,我也会收到回复,但错误似乎出在 Ksoap2 解析响应中。
我相信这是导致错误的响应的这一部分:
<data soapenc:arrayType="xsd:anyType[][2]" xsi:type="soapenc:Array" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
Ksoap2 认为 anyType[][2] 的 ][2 应该是一个整数。
这是 ksoap2 中的错误吗?有解决方法吗?
最佳答案
来自 ksoap v2.1.2 的来源:这是导致 NumberFormatException
的 SoapSerializationEnvelope.getIndex(String value, int start, int dflt) 方法:
private int getIndex(String value, int start, int dflt) {
if (value == null)
return dflt;
return value.length() - start < 3 ? dflt : Integer.parseInt(value.substring(start + 1, value.length() - 1));
}
这是 v2.0.1 中的 SoapSerializationEnvelope.getIndex(String value, int start, int dflt) 方法:
private int getIndex(String value, int start, int dflt) {
if (value == null)
return dflt;
return value.length() - start < 3
? dflt
: Integer.parseInt(value.substring(start + 1, value.length() - 1));
}
查看 http://sourceforge.net/p/kobjects/bugs/14/ 提交的错误报告。它和你的问题一样。错误报告提到了 2.0.1 版本。
getIndex(String value, int start, int dflt)
在 2.0.1 和 2.1.2 版本之间没有变化。另一份报告:Can't handle two dimensional arrays
关于Android KSoap2 和数组问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17792654/