SOAP响应
<?xml version="1.0" encoding="UTF-8"?>
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:getItemTypesResponse xmlns:ns2="http://Product/">
<return>Laptop</return>
<return>Netbook</return>
</ns2:getItemTypesResponse>
</S:Body>
如何在android中解析这个SOAP响应?
这是我的代码。
for(int i =0 ; i<count;i++){
//SoapObject inner= (SoapObject)outer.getProperty(i);
String s = null;
s = outer.getProperty(i).toString();
result.add(s);
}
答案 0 :(得分:1)
您需要的只是:http://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#sending/receiving_array_of_complex_types_or_primitives
尝试创建对象实现KvmSerializable
答案 1 :(得分:1)
创建一个实现KvmSerializeable
:
public class Import implements KvmSerializable {
String test;
public Import() {}
public Import (String test) {
this.test = test;
}
public Object getProperty(int arg0) {
switch (arg0) {
case 0:
return test;
default:
return test;
}
}
public int getPropertyCount() {
return 1;
}
public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {
switch (arg0) {
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "test";
break;
default:
break;
}
}
public void setProperty(int arg0, Object arg1) {
switch (arg0) {
case 0:
test = (String) arg1;
break;
}
}
}
只需更改变量即可满足您的需求。然后:
SoapObject soapObject = new SoapObject(NAMESPACE_NIST_IMPORT,
METHOD_NAME_NIST_IMPORT);
Import import= new Import("Hello, World!");
PropertyInfo pi = new PropertyInfo();
pi.setName("req");
pi.setValue(import);
pi.setType(import.getClass());
soapObject.addProperty(pi);
SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
soapSerializationEnvelope.setOutputSoapObject(soapObject);
soapSerializationEnvelope.addMapping(NAMESPACE, "Import", new Import().getClass());
解析回复:
SoapObject response = (SoapObject)soapSerializationEnvelope.getResponse();
Import.test= response.getProperty(0).toString();