1

我收到的 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。

我该如何解决这个问题。

4

3 回答 3

2

我认为这段代码会对你有所帮助。

int count = root.getPropertyCount();

for(int i=0; i< count; i++)
{
    SoapObject response = (SoapObject) envelope.getResponse();                          
    SoapObject root = (SoapObject) response.getProperty("UserDetail");
    String userID = (root.getPropertyAsString("UserID"));  
    String userName = (root.getPropertyAsString("UserName"));
}
于 2015-03-31T06:56:47.793 回答
0

(SoapObject) root.getProperty("UserDetail");总是相同的位置root

于 2013-05-27T21:27:03.837 回答
0

我可以通过以下方式解决问题:

for(int i = 0; i < root.getPropertyCount(); i++)
            {
                Object property = root.getProperty(i);
                 if (property instanceof SoapObject)
                   {
                     SoapObject category_list = (SoapObject) property;
                     String strVehNo = category_list.getProperty("VehicleNo").toString();
                     String strVehId = category_list.getProperty("VehicleID").toString();
                     vector.addElement(strVehNo);
                     vector.addElement(strVehId);
                   }
            }
        }
于 2013-05-29T03:45:36.013 回答