When to use Soapobject and SoapPrimitive

丶灬走出姿态 提交于 2019-12-03 17:45:17

问题


I have been working with ksoap2 lately.

I am still confused whether what is the EXACT difference between SoapObject and SoapPrimitive.

And when to use them.

I guess its something related to string and arrays. Is it true?

I found some links but got confused.

Can anyone tell me the difference and when to use which one in the simplest form of English?

Thanks :)


回答1:


SoapObject is used when we need to get the Response for a Class type, like Customer, Product, etc. (From the SoapObject you need to iterate over the values inside the SoapResponse.) SoapPrimitive is used for Primitive datatypes like Integer, Boolean.

For example, in the following code I am expecting a Boolean value from SoapResponse:

SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
Boolean status = Boolean.valueOf(response.toString());

And in the following code, I need to get the Response as an Object:

SoapObject response = (SoapObject) envelope.getResponse();
Log.d("Response", response.toString());
int count = response.getPropertyCount();

for (int i = 0; i < count; i++) {
    userObj = new User(response.getProperty(1).toString(),
                       Double.parseDouble(response.getProperty(2).toString()));  
}


来源:https://stackoverflow.com/questions/16583796/when-to-use-soapobject-and-soapprimitive

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