我的肥皂响应如下所示:
<return>
<allergies>
<description>Allergy on Skynet</description>
</allergies>
<allergies>
<description>Allergy 2</description>
</allergies>
<allergies>
<description>Allergy 3</description>
</allergies>
<dateOfBirth>1989-02-28T00:00:00Z</dateOfBirth>
<diagnosys>Something bad</diagnosys>
<firstName>Sara</firstName>
<gender>Female</gender>
<id>2</id>
<lastName>Conor</lastName>
<medicationList>
<description>Medication 1</description>
<dossage>34ml</dossage>
<id>4</id>
<medicationTimes>
<from>1970-01-01T00:00:00Z</from>
<to>1970-01-01T00:30:00Z</to>
</medicationTimes>
<medicationTimes>
<from>1970-01-01T01:00:00Z</from>
<to>1970-01-01T02:00:00Z</to>
</medicationTimes>
<otherInfo>Something</otherInfo>
<strength>strong</strength>
</medicationList>
<medicationList>
<description>Medication 2</description>
<dossage>10 ml</dossage>
<id>5</id>
<medicationTimes>
<from>1970-01-01T20:15:00Z</from>
<to>1970-01-01T22:30:00Z</to>
</medicationTimes>
<otherInfo>bla bla bla</otherInfo>
<strength>very strong</strength>
</medicationList>
<medicationList>
<description>Aspirin</description>
<dossage>34ml</dossage>
<id>6</id>
<otherInfo>bla bla bla</otherInfo>
<strength>very strong</strength>
</medicationList>
</return>
我必须遍历所有内容并列出清单。为此,我正在执行以下操作:
SoapObject response = (SoapObject) envelope.bodyIn;
object = (SoapObject)response.getProperty("return");
details.setFirstName(object.getProperty("firstName").toString());
details.setLastName(object.getProperty("lastName").toString());
ArrayList<PatientMedicine> medicineList=new ArrayList<PatientMedicine>();
PatientMedicine medicine=new PatientMedicine();
SoapObject oMedicationList=(SoapObject) object.getPropertySafely("medicationList");
// SoapObject oMedicationTime=(SoapObject)oMedicationList.getPropertySafely("medicationTimes");
if(oMedicationList!=null){
for(int k=0;k<oMedicationList.getPropertyCount();k++){
//SoapObject test=(SoapObject)oMedicationList.getProperty(k); //I can not do this..this gives error.
SoapObject oMedicationTime=(SoapObject)oMedicationList.getProperty("medicationTimes");
medicine.setDescription(oMedicationList.getPrimitivePropertySafelyAsString("description"));
medicine.setDossage(oMedicationList.getPrimitivePropertySafelyAsString("dossage"));
medicine.setStrength(oMedicationList.getPrimitivePropertySafelyAsString("strength"));
medicineList.add(medicine);
}
details.setMedicineList(medicineList);
现在的问题是,从上面的代码中,我只得到了 n 次的第一个对象。不是每个项目。
我在哪里做错了?如果有人可以帮助我,那就太好了。