有没有办法解析这个肥皂反应?

时间:2016-09-26 17:51:41

标签: android xml soap ksoap

我的代码

protected void getComplaits(String Payroll_no) {
    SoapObject request = new SoapObject(sd.NAMESPACE, sd.GET_COMPLAINTS_LIST);
    PropertyInfo Payroll_info = new PropertyInfo();
    Payroll_info.setName("Payroll_no");
    Payroll_info.setValue(Payroll_no);
    Payroll_info.setType(double.class);
    request.addProperty(Payroll_info);

    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(sd.URL);
    try {
        androidHttpTransport.call(sd.GET_COMPLAINTS_LIST_SOAP_ACTION, envelope);
        SoapObject result = (SoapObject) envelope.bodyIn;
        result1 =result.toString();

    } catch (Exception e) {
        result1 = e.toString();
    }

}

这是我的肥皂反应

Get_Complaints_listResponse
{Get_Complaints_listResult=anyType
{schema=anyType
{element=anyType
{complexType=anyType
{choice=anyType
{element=anyType
{complexType=anyType
{sequence=anyType
{element=anyType{}; element=anyType {}; element=anyType{}; element=anyType{}; 
}; 
}; 
}; 
}; 
}; 
}; 
}; 
diffgram=anyType
{DocumentElement=anyType
{
Complaints_list=anyType{
COMPLAINT_NO=5951113; COMPLAINT_TYPE=NSI; CONSUMER_TYPE=M; COMPLAINT_TIME=0500; }; 

Complaints_list=anyType{
COMPLAINT_NO=403730614; COMPLAINT_TYPE=VLF; CONSUMER_TYPE=M; COMPLAINT_TIME=2340; };
}; 
}; 
};
}

我应该如何获得仅COMPLAINT_NO,COMPLAINT_TYPE,CONSUMER_TYPE,COMPLAINT_TIME数据。 我已经尝试解析但它不起作用,请指导!!!

如何从此字段获取数据,是否有任何库提供这些方法来提取数据!!

1 个答案:

答案 0 :(得分:0)

我在阅读了几篇文章后找到了解决方案。谢谢你,Stack overflow成员

 try {
        androidHttpTransport.call(sd.GET_COMPLAINTS_LIST_SOAP_ACTION, envelope);
        SoapObject root = (SoapObject) envelope.bodyIn;
        SoapObject t = (SoapObject)root.getProperty(0);
        SoapObject t1 = (SoapObject)t.getProperty(1);
        SoapObject t2 = (SoapObject)t1.getProperty(0);


        for(int i = 0;i < t2.getPropertyCount();i++)
        {
            SoapObject Complaint_list = (SoapObject) t2.getProperty(i);
            SoapPrimitive complaint_no = (SoapPrimitive)Complaint_list.getProperty(0);
            SoapPrimitive complaint_type = (SoapPrimitive)Complaint_list.getProperty(1);
            SoapPrimitive consumer_type = (SoapPrimitive)Complaint_list.getProperty(2);
            SoapPrimitive complaint_time = (SoapPrimitive)Complaint_list.getProperty(3);

            Log.i("complaint_no",complaint_no.toString());
            Log.i("complaint_type",complaint_type.toString());
            Log.i("consumer_type",consumer_type.toString());
            Log.i("complaint_time",consumer_type.toString());

        }
    } catch (Exception e) {
        result1 = e.toString();
    }