簡體   English   中英

Android Ksoap2 無法序列化 int 數組

[英]Android Ksoap2 cannot serialize Array of int

我在嘗試將包含 int 數組的 object 發送到 .net web 服務時遇到問題。

這是我的 XML

      <Token>string</Token>
      <Type>string</Type>
      <DownloadSelectionInfo>
        <filesListCount>int</filesListCount>
        <filesList>
          <int>int</int>
          <int>int</int>
        </filesList>
        <Filename>string</Filename>
      </DownloadSelectionInfo>

這是我的序列化 class

public class DownloadSelectionInfo implements KvmSerializable {
    ....
    private ArrayList<Integer> filesList;
    ...
    public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
          ...
            case 1:
                info.type = PropertyInfo.VECTOR_CLASS;;
                info.name = "filesList";
                break;
         ...
    }

    public void setProperty(int index, Object value) {
              ....
            case 1:
                filesList.add(Integer.parseInt(value.toString()));
            .....
    }
}

這里的網絡服務調用


 //add filesList
 SoapObject soFilesList = new SoapObject(Util.getWebService(),"filesList");
 for(Integer i : downloadSelectionInfo.getFilesList()){
     soFilesList.addProperty("int",i);
 }
 soDownloadSelectionInfo.addSoapObject(soFilesList);

 PropertyInfo pi = new PropertyInfo();
 pi.setName("DownloadSelectionInfo");
 pi.setValue(downloadSelectionInfo);
 pi.setType(DownloadSelectionInfo.class);
 Request.addProperty(pi);

 soapEnvelope.addMapping(Util.getWebService(), "DownloadSelectionInfo",DownloadSelectionInfo.class);

但我收到錯誤“java.lang.RuntimeException:無法序列化 [10,9,1]”。 有什么幫助嗎?

我找到了解決方案:

添加 soapEnvelope.addMapping(Util.getWebServiceGed(), "filesList", Vector.class);

並將 arrayList< Integer > 更改為 Vector< Integer >

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM