Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SOapObject Issues Android

Tags:

android

ksoap2

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

like image 868
Udaykiran Avatar asked Sep 29 '26 07:09

Udaykiran


2 Answers

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"

like image 82
PedroAGSantos Avatar answered Sep 30 '26 20:09

PedroAGSantos


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

like image 39
Friz14 Avatar answered Sep 30 '26 21:09

Friz14



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!