Gunaseelan Gunaseelan - 2 months ago 29
Android Question

Ksoap2 returns anytype{} instead of null

This is my asynchronous code

@Override
protected SoapObject doInBackground(String... params) {
try {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
request.addProperty("ID", "0014");
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.implicitTypes = false;
envelope.dotNet = true;
HttpTransportSE transport = new HttpTransportSE(URL);

try {
transport.call(SOAP_ACTION, envelope);
} catch (Exception e) {
e.printStackTrace();
}
try {
SoapFault fault = (SoapFault) envelope.bodyIn;
System.out.println("fault in getdata : " + fault);
} catch (Exception e) {
e.printStackTrace();
}
try {
result = (SoapObject) envelope.bodyIn;
System.out.println("result in getdata : " + result);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
// System.out.println("Exception : " + e.toString());
}
return result;
}


And my response is

result in getdata : Getesponse{GetResult=anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyType
{element=anyType{complexType=anyType{sequence=anyType{element=anyType{}; element=anyType{}; element=anyType{};
element=anyType{}; element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; }; }; };
diffgram=anyType{DocumentElement=anyType{Table1=anyType{Name=Sathish1; Subject=anyType{}; ID=0014; }; }; }; }; }


Here I want subject as
null
instead of
anyType{}
. Is there any better idea other than checking using
if
statement friends?

Answer

When you later parse the result, use getPrimitiveProperty instead of getProperty. It is essentially the same, but fixes this kind of error.