Search code examples
androidksoap2

SOapObject Issues Android


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


Solution

  • 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"