Android 将自定义对象的ArrayList传递给kSOAP函数
这是调用服务器中的函数以执行某些任务的函数。但我必须传入一个ArrayList和一个字符串值。我无法将ArrayList传递到服务器。谁能告诉我该怎么办Android 将自定义对象的ArrayList传递给kSOAP函数,android,ksoap,Android,Ksoap,这是调用服务器中的函数以执行某些任务的函数。但我必须传入一个ArrayList和一个字符串值。我无法将ArrayList传递到服务器。谁能告诉我该怎么办 public void findLocation(ArrayList<APData> apdatalist, String profilename){ SoapObject request = new SoapObject(NAMESPACE, "FindLocation"); PropertyInfo quote
public void findLocation(ArrayList<APData> apdatalist, String profilename){
SoapObject request = new SoapObject(NAMESPACE, "FindLocation");
PropertyInfo quotesProperty = new PropertyInfo();
quotesProperty.setName("profileName");
quotesProperty.setValue(profilename);
quotesProperty.setType(String.class);
request.addProperty(quotesProperty);
request.addProperty("AP_List", APData.class);
envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE httpRequest = new HttpTransportSE(URL);
httpRequest.debug = true;
String result = "";
try
{
httpRequest.call(SOAP_ACTION, envelope);
Log.e("Request",httpRequest.requestDump.toString());
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
Log.e("Response",httpRequest.responseDump.toString());
result = response.toString();
if(result == null){
Log.e("AndroidRuntime", "No location result is return!");
}
}
catch(Exception e)
{
e.printStackTrace();
}
//return temp;
}
public void findLocation(ArrayList apdatalist,String profilename){
SoapObject请求=新的SoapObject(名称空间,“FindLocation”);
PropertyInfo QuoteProperty=新的PropertyInfo();
quoteProperty.setName(“profileName”);
QuoteProperty.setValue(profilename);
quoteProperty.setType(String.class);
request.addProperty(quotesProperty);
addProperty(“AP_列表”,APData.class);
信封=新的SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet=true;
envelope.setOutputSoapObject(请求);
HttpTransportSE httpRequest=新的HttpTransportSE(URL);
httpRequest.debug=true;
字符串结果=”;
尝试
{
httpRequest.call(SOAP\u操作,信封);
Log.e(“Request”,httpRequest.requestDump.toString());
SoapPrimitive响应=(SoapPrimitive)信封.getResponse();
Log.e(“Response”,httpRequest.responseDump.toString());
结果=response.toString();
如果(结果==null){
Log.e(“AndroidRuntime”,“没有返回位置结果!”);
}
}
捕获(例外e)
{
e、 printStackTrace();
}
//返回温度;
}
我找到了一个可能的解决方案。我修改了SoapSerializationEnvelope类来处理ArrayList。
我修改了方法
public void writeObjectBody(XmlSerializer writer,KvmSerializable obj)
public void writeObjectBody(XmlSerializer编写器,KvmSerializable obj)引发IOException
{
//添加了用于解析KvmSerializable对象属性的代码
int cnt=obj.getPropertyCount();
PropertyInfo info=新的PropertyInfo();
对于(int i=0;i
这似乎对我有效我找到了一个可能的解决方案。我修改了SoapSerializationEnvelope类来处理ArrayList。 我修改了方法
public void writeObjectBody(XmlSerializer writer,KvmSerializable obj)
public void writeObjectBody(XmlSerializer编写器,KvmSerializable obj)引发IOException
{
//添加了用于解析KvmSerializable对象属性的代码
int cnt=obj.getPropertyCount();
PropertyInfo info=新的PropertyInfo();
对于(int i=0;i
这似乎对我有用你有没有找到答案?我也有同样的问题。对不起。。。还没有找到解决办法。你有没有找到答案?我也有同样的问题。对不起。。。如何以及在何处调用此方法如何以及在何处调用此方法
public void writeObjectBody(XmlSerializer writer, KvmSerializable obj) throws IOException
{
// Added this code for parsing attributes of KvmSerializable objects
int cnt = obj.getPropertyCount();
PropertyInfo info = new PropertyInfo();
for (int i = 0; i < cnt; i++)
{
Object prop = obj.getProperty(i);
if(!(prop instanceof SoapObject)) {
// prop is a PropertyInfo
obj.getPropertyInfo(i, properties, info);
// Added this code to parse ArrayList objects in requests
if(prop instanceof ArrayList<?>){
ArrayList<?> values = (ArrayList<?>)prop;
for(Object o : values){
writer.startTag(info.namespace, info.name);
writeProperty(writer, o, info);
writer.endTag(info.namespace, info.name);
}
}else if ((info.flags & PropertyInfo.TRANSIENT) == 0)
{
writer.startTag(info.namespace, info.name);
writeProperty(writer, obj.getProperty(i), info);
writer.endTag(info.namespace, info.name);
}
} else {
// prop is a SoapObject
SoapObject nestedSoap = (SoapObject)prop;
writer.startTag(nestedSoap.getNamespace(), nestedSoap.getName());
writeObjectBody(writer, nestedSoap);
writer.endTag(nestedSoap.getNamespace(), nestedSoap.getName());
}
}
}