我目前正在尝试使用ksoap2编写一个Web服务客户端.web服务返回复杂的数据类型。我需要使用我的webservice客户端获取该对象。
请提供一些指导来实现同样的目标。
答案 0 :(得分:0)
如果复杂数据类型是层次结构,则创建SoapObject,直到获得最后一个级别。例如,以下代码段使用三个SoapObject来获取soap响应的键和值:
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
HttpTransportSE transport = new HttpTransportSE(URL);
transport.debug = true;
transport.call(SOAP_ACTION+"createSubmission", envelope);
SoapObject so = (SoapObject) envelope.bodyIn;
Log.i("data:SO", so.toString());
SoapObject so2 = (SoapObject)so.getProperty(0);
Log.i("data:SO2", so2.toString());
int count = so.getPropertyCount();
for(int i = 0; i < count; ++i) {
SoapObject so3 = (SoapObject)so.getProperty(i);
Log.i("data", (String)so3.getProperty(0)+" extra");
String key = (String) so2.getProperty(0);
Object val = so2.getProperty(1);
data.put(key, val);
}