gpt4 book ai didi

android - 如何在 KSOAP2 中解析复杂的 SOAP 响应

转载 作者:行者123 更新时间:2023-11-29 21:42:11 25 4
gpt4 key购买 nike

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

现在,根据这个复杂的响应,我需要车辆编号并将它们存储在向量中。目前使用我上面的代码,我多次获得第一组响应。意味着向量中多次添加相同的车辆编号。

我该如何解决这个问题。

最佳答案

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

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"));
}

关于android - 如何在 KSOAP2 中解析复杂的 SOAP 响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16780245/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com