4

我正在使用 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 应该是一个 int。

这是 ksoap2 中的错误吗?有解决方法吗?

4

2 回答 2

1

我认为它期望在 soapenc:arrayType="xsd:anyType[][2]" 的第一个方括号中有一个 int 值

由于它没有获得任何 int 值,因此出现了异常。

于 2013-08-01T02:39:53.093 回答
0

07-22 11:12:57.738: W/System.err(9582): 在 org.ksoap2.serialization.SoapSerializationEnvelope.getIndex(SoapSerializationEnvelope.java:287)

从 ksoap v2.1.2 的源代码:这是 SoapSerializationEnvelope.getIndex(String value, int start, int dflt) 方法导致NumberFormatException

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 版本之间没有变化。

另一份报告:无法处理二维数组

于 2013-07-28T19:27:00.383 回答