2016-09-26 91 views
0

我的代碼有沒有什麼辦法解析這個肥皂響應?

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

} 

這是我的SOAP響應

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數據。 我已經嘗試解析但它不工作,請指導!

我應該如何從這個字段獲取數據,是否有任何庫提供這些方法來提取數據!

回答

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