到目前爲止,我已經設法連接到一個Web服務並獲得我的SoapObject響應,但是我無法縮小一個很好的,乾淨的解析方式。搜索互聯網並沒有真正產生太多的結果,每個人都有不同的方式和不同的流程,通常針對他們自己的Web服務,使其成爲一次性使用類型的解決方案。基本上,下面是我從一個Web服務有沒有更好的解析Android中的SoapObject的方法
anyType{
schema=anyType{
element=anyType{
complexType=anyType{
choice=anyType{
element=anyType{
complexType=anyType{
sequence=anyType{
element=anyType{};
element=anyType{};
element=anyType{};
element=anyType{}; }; }; }; }; }; }; };
diffgram=anyType{
NewDataSet=anyType{
Rep_x0020_Information=anyType{
Login=CorrectLogin; Password=InCorrectPass; }; }; }; }
,基本上我希望能夠解析出剛剛在兩個重要領域(登錄名和密碼)獲得響應。從我閱讀的內容來看,我試着迭代基於屬性計數的SoapObject響應,但似乎並不奏效。當我想我得到的2財產計數響應所以不是我最後做一些這樣的事如下:
SoapObject response=(SoapObject) envelope.getResponse();
if (response != null) {
Log.i("Message", "the response contains: " + response.toString());
SoapObject diffgram = (SoapObject) response.getProperty("diffgram");
SoapObject NewDataSet = (SoapObject) diffgram.getProperty("NewDataSet");
SoapObject RepInfo = (SoapObject) NewDataSet.getProperty("Rep_x0020_Information");
for (int i = 0; i < RepInfo.getPropertyCount(); i++) {
PropertyInfo info = new PropertyInfo();
RepInfo.getPropertyInfo(i, info);
Log.d("Info", info.name + " : " + RepInfo.getProperty(i).toString());
}
//which gives the following message in LogCat
D/Info(716): Login : InCorrectLogin
D/Info(716): Password : InCorrectPass
這個過程的作品,由最後一個循環,我得到了兩個對象我想,但我只是覺得有一個更乾淨的方式來做到這一點。我只問,因爲當我進一步進入這個應用程序時,會有一些更復雜的Web服務調用被創建,我希望能夠在整個應用程序中擁有可重用的內容,而不必爲每個請求構建多個SoapObjects直到我想要的物體。
我想,你可以使用JSONObject,json對解析非常簡單 – Jamshid