我从像这样的soap webserice获得结果。
皂: GetHospitalByPlaceResponse {GetHospitalByPlaceResult = anyType的{医院= {anyType的HID = 1; HospitalName = A J Hospital;地址= Kazhakkoottam; 区=特里凡得琅;国家=喀拉拉邦;城市特里凡得琅=; 地方= Kazhakkoottam; pin码= 695581;手机= 8547468908; }; 医院= {anyType的HID = 2; HospitalName = Suja医院; 地址= Kazhakkoottam;区=特里凡得琅;国家=喀拉拉邦; 城市特里凡得琅=;地方= Kazhakkoottam; pin码= 695581; 手机= 9567288636; };医院= {anyType的HID = 3; HospitalName = C S I 医院;地址= Kazhakkoottam;区=特里凡得琅; 国家=喀拉拉邦;城市特里凡得琅=;地方= Kazhakkoottam; pin码= 695581;手机= 9020210021; }; };}
我不知道如何解析这个以获取hospitalName和Phone 请任何人都可以帮助我 提前致谢
答案 0 :(得分:0)
写一个像这样的方法;
public ArrayList<ArrayList<String>> parseMethod(){
SoapObject so = get_soap_object();
String METHOD_RESULT = "SERVICENAME"+"Result";
ArrayList<ArrayList<String>> fullList= new ArrayList<ArrayList<String>>();
ArrayList<String> hospitalNameList = new ArrayList<String>();
ArrayList<String> phoneList = new ArrayList<String>();
if (so != null) {
try {
PropertyInfo pi = new PropertyInfo();
so.getPropertyInfo(0, pi);
String result_name = pi.getName();
if (METHOD_RESULT.equals(result_name)) {
SoapObject soResult = (SoapObject) so.getProperty(0);
SoapObject soResult2 = (SoapObject) soResult.getProperty("GetHospitalByPlaceResult");
String hospital,phone;
if (soResult != null) {
for (int j = 0; j < soResult2.getPropertyCount(); j++){
SoapObject soResult3 = (SoapObject) soResult2.getProperty(j);
PropertyInfo pi_name = new PropertyInfo();
soResult2.getPropertyInfo(j, pi_name);
String propertyArray = pi_name.getName();
if(propertyArray.equals("Hospital")){
for(int i = 0; i < soResult3.getPropertyCount() ; i++){
PropertyInfo pi_sr = new PropertyInfo();
soResult3.getPropertyInfo(i, pi_sr);
String propertyName = pi_sr.getName();
if ("HospitalName".equals(propertyName)) {
hospitalName= String.valueOf(soResult3.getProperty(propertyName).toString());
hospitalList.add(hospitalName);
}
else if("Phone".equals(propertyName)){
phone = String.valueOf(soResult3.getProperty(propertyName).toString());
phoneList.add(phone);
}
}
}
}
}
}
}
catch (Exception e) {
Log.i("exception", e.toString());
}
}
fullList.add(hospital);
fullList.add(phone);
return fullList;
}