Parse KSoap2 response in android [duplicate]

跟風遠走 提交于 2019-12-17 20:22:58

问题


Possible Duplicate:
Parsing ksoap2 response

So I managed to call a webservice using KSoap2 in android but I can't find a way to parse the response...

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; }; }; 
}

And here's the code I'm using to call the webservice...

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();
        }

Is there any way to parse it "easily" without having to so through every property "manually"? something like a XML parser...


回答1:


Take a look here, I believe this code is optimized for working with complex types and returning arrays of complex types with KSOAP:

Web Service That Returns An Array of Objects With KSOAP




回答2:


You can set up automatic marshalling. Check out the links section on the ksoap2-android project for links to some tutorials.



来源:https://stackoverflow.com/questions/3950862/parse-ksoap2-response-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!