我收到的 SOAP 响应有点复杂。响应是这样的:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<getDetailResponse xmlns="http://saiserviceapp.com/">
<getDetailResult>
<UserDetail>
<UserID>int</UserID>
<VehicleID>int</VehicleID>
<UserName>string</UserName>
<VehicleNo>string</VehicleNo>
<ModelID>int</ModelID>
<VariantID>int</VariantID>
<Color>string</Color>
<DOP>dateTime</DOP>
<InsCompany>string</InsCompany>
<InsExpire>dateTime</InsExpire>
<ContactNo>long</ContactNo>
<DInsExpire>dateTime</DInsExpire>
</UserDetail>
<UserDetail>
<UserID>int</UserID>
<VehicleID>int</VehicleID>
<UserName>string</UserName>
<VehicleNo>string</VehicleNo>
<ModelID>int</ModelID>
<VariantID>int</VariantID>
<Color>string</Color>
<DOP>dateTime</DOP>
<InsCompany>string</InsCompany>
<InsExpire>dateTime</InsExpire>
<ContactNo>long</ContactNo>
<DInsExpire>dateTime</DInsExpire>
</UserDetail>
</getDetailResult>
</getDetailResponse>
</soap:Body>
</soap:Envelope>
现在解析它我写了这段代码:
resultRequestSOAP = (SoapObject)envelope.bodyIn;
SoapObject root = (SoapObject) resultRequestSOAP.getProperty(mStrProperty);
SoapObject childObj[] = new SoapObject[root.getPropertyCount()];
for(int i = 0; i < root.getPropertyCount(); i++)
{
childObj[i] = (SoapObject) root.getProperty("UserDetail");
vector.addElement(childObj[i].getProperty(3));
}
在这里,我在转换为字符串后得到根值,如下所示:
anyType
{
UserDetail=
anyType{
UserID=10884;
VehicleID=507;
UserName=ffasdd;
VehicleNo=GJGJGJG;
ModelID=0;
VariantID=0;
DOP=0001-01-01T00:00:00;
InsExpire=null;
ContactNo=8888555522;
DInsExpire=0001-01-01T00:00:00;
};
UserDetail=
anyType{
UserID=10884;
VehicleID=508;
UserName=ffasdd;
VehicleNo=HGHGGHJ;
ModelID=0;
VariantID=0;
DOP=0001-01-01T00:00:00;
InsExpire=null;
ContactNo=8888555522;
DInsExpire=0001-01-01T00:00:00;
};
}
现在从这个复杂的响应中,我想要车辆编号并将它们存储在向量中。目前使用我上面的代码,我多次收到第一组响应。表示在向量中多次添加相同的vehicleNo。
我该如何解决这个问题。