SOapObject Issues Android

微笑、不失礼 提交于 2019-12-23 17:34:07

问题


Am getting Soap response using as Soap Object and retrieving properties. see this below code

SoapObject returnObj = (SoapObject)response.getProperty("GetAllDocumentsResult");
                 // Integer id = Integer.valueOf(returnObj.getProperty("id");

                  for(int i=0;i<returnObj.getPropertyCount();i++) {
                      SoapObject persondetails = (SoapObject)returnObj.getProperty(i);



                      SoapPrimitive videoname = (SoapPrimitive)persondetails.getProperty("PDFFileName");

am retrieving each videoname from persondetails object. but for some persons videoname tag is absent in response.

How to check validate condition such that if a particular property exists in soapobject ?

Thanks


回答1:


Hi you ca use one new thing that exists in new library from ksoap2 android

SoapObject videoname = (SoapObject)persondetails.getPropertySafely("PDFFileName");

if you want the string you can do something like these

String  videoname =persondetails.getPropertySafelyAsString("PDFFileName");

or even if tag is not there place something by default :D

String videoname = persondetails.getPropertySafelyAsString("PDFFileName","NOTHING");

if you don't have go "here http://code.google.com/p/ksoap2-android/source/browse/m2-repo/com/google/code/ksoap2-android/ksoap2-android-assembly/2.5.7/ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar"




回答2:


you can use a try catch or with the debug check the propieties who send you



来源:https://stackoverflow.com/questions/6787543/soapobject-issues-android

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!