我正在开发一个Android应用程序,我需要将一个ArrayList作为参数传递给提供Web服务的SOAP函数。这是我使用的代码:
public boolean addToCart(String username, ArrayList<String> itemsSelected, ArrayList<Integer> idsSelected) throws ServerOfflineException {
String METHOD_NAME = "addToCart";
String SOAP_ACTION = "\"" + NAMESPACE + METHOD_NAME + "\"";
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
PropertyInfo usernameInfo = new PropertyInfo();
usernameInfo.setName("arg0");
usernameInfo.setValue(username);
PropertyInfo itemsInfo = new PropertyInfo();
itemsInfo.setName("arg1");
itemsInfo.setValue(itemsSelected);
PropertyInfo idsInfo = new PropertyInfo();
idsInfo.setName("arg2");
idsInfo.setValue(idsSelected);
request.addProperty(usernameInfo);
request.addProperty(itemsInfo);
request.addProperty(idsInfo);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE ht = new HttpTransportSE(URL);
ht.call(SOAP_ACTION, envelope);
SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
String responseData = response.toString();
if (responseData.equals("true")){
return true;
}
else if (responseData.equals("false")){
return false;
}
} catch (Exception e) {
Log.i("Error:" , e.getMessage());
if (e instanceof SocketException) {
throw new ServerOfflineException("Server Offline");
}
}
return false;
}
但是,我收到错误 ArrayLists无法序列化。有谁知道我应该做什么?