Android KSoap2和Array问题

时间:2013-07-22 16:23:10

标签: android soap ksoap2

我正在使用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认为[2]任何类型[] [2]应该是一个int。

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

2 个答案:

答案 0 :(得分:1)

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

由于它没有得到任何int值,所以异常就出现了。

答案 1 :(得分:0)

  

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

从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。版本2.0.1和2.1.2之间的getIndex(String value, int start, int dflt)没有变化。

另一份报告:Can't handle two dimensional arrays