解析Android的KSoap2响应 [英] Parse KSoap2 response in android

查看:132
本文介绍了解析Android的KSoap2响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
  解析ksoap2响应

所以,我设法调用Android的使用KSoap2一个web服务,但我不能找到一种方法来解析响应...

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

和这里的code我使用调用Web服务...

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

有没有什么办法可以轻松地解析它,而不必透过每个属性手动?就像一个XML解析器...

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

推荐答案

看看这里,我相信这code是复杂类型​​的工作,返回复杂类型的数组与KSOAP优化:

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

Web服务,它返回一个对象数组随着KSOAP

这篇关于解析Android的KSoap2响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆