When to use Soapobject and SoapPrimitive

后端 未结 1 2079
半阙折子戏
半阙折子戏 2021-02-08 00:32

I have been working with ksoap2 lately.

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

1条回答
  •  独厮守ぢ
    2021-02-08 01:38

    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()));  
    }
    

    0 讨论(0)
提交回复
热议问题