0

我有一个 Android APP 和一个 SOAPWebservice。我试图在他们的整数数组之间发送,但 Android Logcat 说:

06-17 15:32:34.355: W/System.err(3107): java.lang.RuntimeException: Cannot serialize: [Ljava.lang.Integer;@42046ff8
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:664)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeProperty(SoapSerializationEnvelope.java:649)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:595)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeObjectBody(SoapSerializationEnvelope.java:573)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeElement(SoapSerializationEnvelope.java:658)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.serialization.SoapSerializationEnvelope.writeBody(SoapSerializationEnvelope.java:555)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.SoapEnvelope.write  (SoapEnvelope.java:205)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.transport.Transport.createRequestData(Transport.java:134)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:144)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:116)
06-17 15:32:34.365: W/System.err(3107):     at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:111)

如果我不能序列化数据,我如何发送一堆整数?

ANDROID 代码(异步任务)

@Override
protected Integer doInBackground(Object... params) {

    try {       

        OSS_APPServiceCredentials wsc = new OSS_APPServiceCredentials("startUpdate");

        request = new SoapObject(wsc.init().get(1), wsc.init().get(0));

        request.addProperty("ParameterA", (String)params[0]);           
        request.addProperty("ParameterB", (Integer[])params[1]);

        envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

        OSS_PermitAllSSLConnections.allowAllSSL();
        KeepAliveHttpsTransportSE androidHttpTransport = new KeepAliveHttpsTransportSE(wsc.init().get(3),Integer.parseInt(wsc.init().get(5)), wsc.init().get(4), Integer.parseInt(wsc.init().get(6)));

        androidHttpTransport.call(wsc.init().get(2), envelope); 
        Object result = envelope.getResponse();
        Integer res = Integer.parseInt(result.toString());

        return res;
    } 

    catch (Exception E) {
        E.printStackTrace();
    }
    return null;
}

谢谢!

编辑:

我试图这样做:

BASE64Decoder decoder = new BASE64Decoder();
byte[] bytes = decoder.decodeBuffer(permissions);

int[] a = new int[bytes.length / 4];
ByteBuffer.wrap(bytes).asIntBuffer().get(a);

但是 Eclipse(在 WebService 中)说这个错误,我不知道为什么!

The method wrap(byte[]) is undefined for the type ByteBuffer

编辑:

最后我解决了这个问题。只有我需要导入:

import java.nio.ByteBuffer;
4

1 回答 1

4

您可以使用 ByteBuffer 将 int[] 转换为 byte[]

    int[] a = { 1, 2, 3 };
    ByteBuffer bb = ByteBuffer.allocate(a.length * 4);
    bb.asIntBuffer().put(a);
    byte[] bytes = bb1.array();

将 byte[] 发送到服务器并将其转换回 int[]

    int[] a = new int[bytes.length / 4];
    ByteBuffer.wrap(bytes).asIntBuffer().get(a);
于 2013-06-17T13:49:31.223 回答