如何存储和解析 soap 对象响应
How to store and parse soap object response
我正在使用 soap 从服务器获取响应。我正在尝试接收一些银行 information.from 响应转储,我得到了完美的 response.But 我不知道如何存储和解析这个对象。
public void getbankinformation(String username,String password)
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//Property which holds input parameters
PropertyInfo name = new PropertyInfo();
name.setName("userName");
name.setValue(username);
name.setType(String.class);
request.addProperty(name);
PropertyInfo pass = new PropertyInfo();
pass.setName("password");
pass.setValue(password);
pass.setType(String.class);
request.addProperty(pass);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try{
HttpTransportSE httpTransport=new HttpTransportSE(URL);
httpTransport.debug=true;
httpTransport.call(NAMESPACE+METHOD_NAME, envelope);
Log.d(TA,"HTTP Request: \n"+ httpTransport.requestDump);
Log.d(TAE,"HTTP Response: \n"+ httpTransport.responseDump);
SoapObject result=(SoapObject)envelope.bodyIn;
String[] testValues=new String[result.getPropertyCount()];
for(int i=0;i<result.getPropertyCount();i++)
{
testValues[i]=result.getProperty(i).toString();
}
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
这是我在 logcat 中显示的回复:
<?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>
<GetBankInformationResponse xmlns="http://QuickManageITCL.org/">
<GetBankInformationResult>
<BankObject>
<RID>string</RID>
<ID>string</ID>
<ShortName>string</ShortName>
<Name>string</Name>
<Address>string</Address>
<BankTypeID>string</BankTypeID>
<Note>string</Note>
<CreatorUserID>string</CreatorUserID>
<OranizationLogo>base64Binary</OranizationLogo>
</BankObject>
<BankObject>
<RID>string</RID>
<ID>string</ID>
<ShortName>string</ShortName>
<Name>string</Name>
<Address>string</Address>
<BankTypeID>string</BankTypeID>
<Note>string</Note>
<CreatorUserID>string</CreatorUserID>
<OranizationLogo>base64Binary</OranizationLogo>
</BankObject>
</GetBankInformationResult>
</GetBankInformationResponse>
</soap:Body>
</soap:Envelope>
这是我得到的 soap 响应格式:
anyType{
BankObject=
anyType{
ID=001;
ShortName=ABBL;
Name=Arab Bangladesh Bank Limited;
Address=Dhaka;
BankTypeID=033;
Note=anyType{};
};
BankObject=
anyType{
ID=032;
ShortName=BCBL;
Name=Bangladesh Commerce Bank Ltd.;
Address=anyType{};
BankTypeID=033;
Note=anyType{};
};
BankObject=
anyType{
ID=033;
ShortName=BPO;
Name=Bangladesh Post Office;
Address=anyType{};
BankTypeID=031;
Note=anyType{};
};
BankObject=
anyType{
ID=027;
ShortName=BAL;
Name=Bank Asia Limited;
Address=anyType{};
BankTypeID=033;
Note=anyType{};
};
BankObject=anyType{ID=002; ShortName=Basic; Name=Basic Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=003; ShortName=BRAC; Name=BRAC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=004; ShortName=CBL; Name=City Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=035; ShortName=CBC; Name=Commercial Bank of Ceylon; Address=anyType{}; BankTypeID=032; Note=anyType{}; }; BankObject=anyType{ID=023; ShortName=DBL; Name=Dhaka Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=005; ShortName=DBBL; Name=Dutch-Bangla Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=006; ShortName=EBL; Name=Eastern Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=034; ShortName=EXBL; Name=Exim Bank; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=038; ShortName=FSIBL; Name=First Security islami Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=007; ShortName=ICB; Name=ICB; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=008; ShortName=IFIC; Name=IFIC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=025; ShortName=IBBL; Name=Islami Bank Bangladesh LTD.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=030; ShortName=ITCL; Name=ITCL; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=031; ShortName=anyType{}; Name=ITCL; Address=Tejgaon; BankTypeID=031; Note=anyType{}; }; BankObject=anyType{ID=009; ShortName=Jamuna; Name=Jamuna; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=010; ShortName=Janata; Name=Janata; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=021; ShortName=MBL; Name=Mercantile Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=011; ShortName=MTBL; Name=Mutual Trust Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=012; ShortName=NBL; Name=National Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=013; ShortName=NCC; Name=NCC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=014; ShortName=One Bank; Name=One Bank Ltd; Address=033; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=037; ShortName=Prime; Name=Prime Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=015; ShortName=Pubali; Name=Pubali Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=017; ShortName=SJBL; Name=Shahjalal Islami Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=026; ShortName=SIBL; Name=Social Islamic Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=018; ShortName=Sonali; Name=Sonali Bank Limited; Address=anyType{}; BankTypeID=036; Note=anyType{}; }; BankObject=anyType{ID=036; ShortName=SEBL; Name=Southeast Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=022; ShortName=SBL; Name=Standard Bank Limited; Address=Dhaka; BankTypeID=033; Note=asdf; }; BankObject=anyType{ID=016; ShortName=SCB; Name=Standard Chartered Bank ; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=019; ShortName=TBL; Name=Trust Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=024; ShortName=UCBL; Name=United Commercial Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=020; ShortName=UBL; Name=Uttara Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; }
我想解析此银行 ID、简称、名称、地址、银行类型 ID、备注等并将其存储到 database.How,我会得到我想要的解析值吗?我需要一个简单的方法。
最简单的 - 每个银行的名称字段:
SoapObject res=(SoapObject)envelope.bodyIn;
SoapObject t=(SoapObject)res.getProperty("GetBankInformationResult");
for(int i=0; i<t.getPropertyCount(); i++){
SoapObject bank=(SoapObject)t.getProperty(i);
String name = bank.getProperty("Name").toString();
}
我正在使用 soap 从服务器获取响应。我正在尝试接收一些银行 information.from 响应转储,我得到了完美的 response.But 我不知道如何存储和解析这个对象。
public void getbankinformation(String username,String password)
{
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
//Property which holds input parameters
PropertyInfo name = new PropertyInfo();
name.setName("userName");
name.setValue(username);
name.setType(String.class);
request.addProperty(name);
PropertyInfo pass = new PropertyInfo();
pass.setName("password");
pass.setValue(password);
pass.setType(String.class);
request.addProperty(pass);
SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
try{
HttpTransportSE httpTransport=new HttpTransportSE(URL);
httpTransport.debug=true;
httpTransport.call(NAMESPACE+METHOD_NAME, envelope);
Log.d(TA,"HTTP Request: \n"+ httpTransport.requestDump);
Log.d(TAE,"HTTP Response: \n"+ httpTransport.responseDump);
SoapObject result=(SoapObject)envelope.bodyIn;
String[] testValues=new String[result.getPropertyCount()];
for(int i=0;i<result.getPropertyCount();i++)
{
testValues[i]=result.getProperty(i).toString();
}
}
catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
这是我在 logcat 中显示的回复:
<?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>
<GetBankInformationResponse xmlns="http://QuickManageITCL.org/">
<GetBankInformationResult>
<BankObject>
<RID>string</RID>
<ID>string</ID>
<ShortName>string</ShortName>
<Name>string</Name>
<Address>string</Address>
<BankTypeID>string</BankTypeID>
<Note>string</Note>
<CreatorUserID>string</CreatorUserID>
<OranizationLogo>base64Binary</OranizationLogo>
</BankObject>
<BankObject>
<RID>string</RID>
<ID>string</ID>
<ShortName>string</ShortName>
<Name>string</Name>
<Address>string</Address>
<BankTypeID>string</BankTypeID>
<Note>string</Note>
<CreatorUserID>string</CreatorUserID>
<OranizationLogo>base64Binary</OranizationLogo>
</BankObject>
</GetBankInformationResult>
</GetBankInformationResponse>
</soap:Body>
</soap:Envelope>
这是我得到的 soap 响应格式:
anyType{
BankObject=
anyType{
ID=001;
ShortName=ABBL;
Name=Arab Bangladesh Bank Limited;
Address=Dhaka;
BankTypeID=033;
Note=anyType{};
};
BankObject=
anyType{
ID=032;
ShortName=BCBL;
Name=Bangladesh Commerce Bank Ltd.;
Address=anyType{};
BankTypeID=033;
Note=anyType{};
};
BankObject=
anyType{
ID=033;
ShortName=BPO;
Name=Bangladesh Post Office;
Address=anyType{};
BankTypeID=031;
Note=anyType{};
};
BankObject=
anyType{
ID=027;
ShortName=BAL;
Name=Bank Asia Limited;
Address=anyType{};
BankTypeID=033;
Note=anyType{};
};
BankObject=anyType{ID=002; ShortName=Basic; Name=Basic Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=003; ShortName=BRAC; Name=BRAC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=004; ShortName=CBL; Name=City Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=035; ShortName=CBC; Name=Commercial Bank of Ceylon; Address=anyType{}; BankTypeID=032; Note=anyType{}; }; BankObject=anyType{ID=023; ShortName=DBL; Name=Dhaka Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=005; ShortName=DBBL; Name=Dutch-Bangla Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=006; ShortName=EBL; Name=Eastern Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=034; ShortName=EXBL; Name=Exim Bank; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=038; ShortName=FSIBL; Name=First Security islami Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=007; ShortName=ICB; Name=ICB; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=008; ShortName=IFIC; Name=IFIC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=025; ShortName=IBBL; Name=Islami Bank Bangladesh LTD.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=030; ShortName=ITCL; Name=ITCL; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=031; ShortName=anyType{}; Name=ITCL; Address=Tejgaon; BankTypeID=031; Note=anyType{}; }; BankObject=anyType{ID=009; ShortName=Jamuna; Name=Jamuna; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=010; ShortName=Janata; Name=Janata; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=021; ShortName=MBL; Name=Mercantile Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=011; ShortName=MTBL; Name=Mutual Trust Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=012; ShortName=NBL; Name=National Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=013; ShortName=NCC; Name=NCC; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=014; ShortName=One Bank; Name=One Bank Ltd; Address=033; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=037; ShortName=Prime; Name=Prime Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=015; ShortName=Pubali; Name=Pubali Bank Ltd.; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=017; ShortName=SJBL; Name=Shahjalal Islami Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=026; ShortName=SIBL; Name=Social Islamic Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=018; ShortName=Sonali; Name=Sonali Bank Limited; Address=anyType{}; BankTypeID=036; Note=anyType{}; }; BankObject=anyType{ID=036; ShortName=SEBL; Name=Southeast Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=022; ShortName=SBL; Name=Standard Bank Limited; Address=Dhaka; BankTypeID=033; Note=asdf; }; BankObject=anyType{ID=016; ShortName=SCB; Name=Standard Chartered Bank ; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=019; ShortName=TBL; Name=Trust Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=024; ShortName=UCBL; Name=United Commercial Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; BankObject=anyType{ID=020; ShortName=UBL; Name=Uttara Bank Limited; Address=anyType{}; BankTypeID=033; Note=anyType{}; }; }
我想解析此银行 ID、简称、名称、地址、银行类型 ID、备注等并将其存储到 database.How,我会得到我想要的解析值吗?我需要一个简单的方法。
最简单的 - 每个银行的名称字段:
SoapObject res=(SoapObject)envelope.bodyIn;
SoapObject t=(SoapObject)res.getProperty("GetBankInformationResult");
for(int i=0; i<t.getPropertyCount(); i++){
SoapObject bank=(SoapObject)t.getProperty(i);
String name = bank.getProperty("Name").toString();
}