可能重复:
解析 ksoap2 响应
所以我设法在android中使用KSoap2调用了一个网络服务,但我找不到解析响应的方法......
So here's what I receive from the webservice
anyType{
WORCCategoriaSubcategoriaRecord=anyType{ssENCategoria=anyType{Id=1; Nome=Problema na rua; }; ssENSubcategoria=anyType{Id=1; Nome=Falta de acesso; Imagem=anyType{}; CategoriaId=1; }; };
WORCCategoriaSubcategoriaRecord=anyType{ssENCategoria=anyType{Id=1; Nome=Problema na rua; }; ssENSubcategoria=anyType{Id=2; Nome=Falta de Passadeira; Imagem=anyType{}; CategoriaId=1; }; };
}
这是我用来调用网络服务的代码......
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//request.addProperty("Celsius", "32");
SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
//soapEnvelope.dotNet = true;
soapEnvelope.setOutputSoapObject(request);
soapEnvelope.dotNet = true;
AndroidHttpTransport aht = new AndroidHttpTransport(URL);
try{
aht.call(SOAP_ACTION, soapEnvelope);
//SoapPrimitive resultString = (SoapPrimitive)soapEnvelope.getResponse();
SoapObject resultsRequestSOAP = (SoapObject) soapEnvelope.bodyIn;
int elementCount = resultsRequestSOAP.getPropertyCount();
if(elementCount>0){
SoapObject element;
for(int i = 0;i<elementCount;i++){
element = (SoapObject)resultsRequestSOAP.getProperty(i);
}
}
}catch(Exception ex){
ex.printStackTrace();
}
有没有办法“轻松”地解析它而不必“手动”通过每个属性?类似于 XML 解析器的东西...