5

可能重复:
解析 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 解析器的东西...

4

2 回答 2

3

看看这里,我相信这段代码已经过优化,可以处理复杂类型并使用 KSOAP 返回复杂类型的数组:

使用 KSOAP 返回对象数组的 Web 服务

于 2010-11-17T11:48:40.860 回答
1

您可以设置自动编组。查看 ksoap2-android 项目的链接部分以获取一些教程的链接。

于 2010-11-04T20:55:38.817 回答