android開發使用ksoap2呼叫webservice步驟
阿新 • • 發佈:2022-03-20
1:要在android上呼叫,我們首先下載ksoap2-android jar包,丟到lib包下,新增依賴
2:接著我們提取出一個請求的工具類SoapConfig
3.在ViewModel中呼叫請求
4 解析請求WebService返回SoapObject 資料解析
try { SoapSerializationEnvelope envelope = (SoapSerializationEnvelope) o; Object ob = envelope.bodyIn; SoapObject soapObject = (SoapObject) envelope.getResponse(); SoapObject str = (SoapObject) soapObject.getProperty(0); SoapObject st1 = (SoapObject) soapObject.getProperty(1); SoapObject str2 = (SoapObject) st1.getProperty(0); List<SimpleType> lists = new ArrayList<>(); for (int i = 0; i < str2.getPropertyCount(); i++) { SoapObject soapObject1 = (SoapObject) str2.getProperty(i); lists.add(new SimpleType(Integer.parseInt(soapObject1.getPropertyAsString("RegionID")), soapObject1.getPropertyAsString("RegionName"))); } Logger.d(String.valueOf(lists.size())); } catch (SoapFault soapFault) { soapFault.printStackTrace(); }