我向您粘贴了一个示例代码,用于解析来自使用 .NET Web 服务的 Ksoap2 的结果。我希望它有所帮助。
创建一个具有如下数据类型的类:
import org.ksoap2.serialization.KvmSerializable;
import org.ksoap2.serialization.PropertyInfo;
public class Provincias implements KvmSerializable {
public int GCPRV;
public String GDPRV;
public int GFCTB;
public Provincias(){}
public Provincias(int gcprv, String gdprv, int gfctb)
{
this.GCPRV=gcprv;
this.GDPRV=gdprv;
this.GFCTB=gfctb;
}
@Override
public Object getProperty(int arg0) {
switch(arg0)
{
case 0:
return GCPRV;
case 1:
return GDPRV;
case 2:
return GFCTB;
}
return null;
}
@Override
public int getPropertyCount() {
return 3;
}
@Override
public void getPropertyInfo(int index, Hashtable arg1, PropertyInfo info) {
switch(index)
{
case 0:
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "GCPRV";
break;
case 1:
info.type = PropertyInfo.STRING_CLASS;
info.name = "GDPRV";
break;
case 2:
info.type = PropertyInfo.INTEGER_CLASS;
info.name = "GFCTB";
break;
default:break;
}
}
获得 SoapObject 响应后,您只需要查询它的属性并将它们绑定到您的类,如下所示:
Provincias[] prov = new Provincias[ObjetoSoap.getPropertyCount()];
for (int i = 0; i < prov.length; i++) {
SoapObject pii = (SoapObject)ObjetoSoap.getProperty(i);
Provincias provincia = new Provincias();
provincia.GCPRV=Integer.parseInt(pii.getProperty(0).toString());
provincia.GDPRV =pii.getProperty(1).toString();
provincia.GFCTB=Integer.parseInt(pii.getProperty(2).toString());
prov[i] = provincia;
}
编辑:这里有方法描述:
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Cargar_Provincias_JavaResponse xmlns="http://tempuri.org/">
<Cargar_Provincias_JavaResult>
<Provincias_Class>
<GCPRV>int</GCPRV>
<GDPRV>string</GDPRV>
<GFCTB>int</GFCTB>
</Provincias_Class>
<Provincias_Class>
<GCPRV>int</GCPRV>
<GDPRV>string</GDPRV>
<GFCTB>int</GFCTB>
</Provincias_Class>
</Cargar_Provincias_JavaResult>
</Cargar_Provincias_JavaResponse>
</soap:Body>
</soap:Envelope>