How can I cast a String to a SoapObject in ksoap2?

前端 未结 3 924
既然无缘
既然无缘 2021-01-07 14:29

In my Android app I use ksoap2 for communication with a server. I download a certain complex sports information structure via soap request and parse it later in my program.<

3条回答
  •  再見小時候
    2021-01-07 14:43

    Lets say, someObject is an object with the members CategoryId, Name, Description. If you are getting these object members in the response, you can save them to someObject by doing this:

    SoapObject response = (SoapObject)envelope.getResponse();
    
    someObject.CategoryId =  Integer.parseInt(response.getProperty(0).toString());
    someObject.Name =  response.getProperty(1).toString();
    someObject.Description = response.getProperty(2).toString();
    

    EDIT:

    Ok I see the problem now.

    To get a soapobject, only way I can think of is:

    1)parse the stored string 2)store all the data fields in local variables

    Parse stored string:
    
    start loop
    int x = something
    string y = something
    double z = something
    end loop
    

    3)create a new object using the variables

    someObject.fieldx = x
    someObject.fieldy = y
    someObject.fieldz = z
    

    4)create a new soapobject

    SoapObject sp_Object = new SoapObject(NAMESPACE, METHOD_NAME);
    

    5)create a propertyinfo using the object in step 3

    PropertyInfo prop = new PropertyInfo();
    prop.setNamespace(NAMESPACE);
    prop.setType(someObject.getClass());
    prop.setValue(someObject);
    

    6)add the propertyinfo to the soapobject in step 4

    sp_Object.addProperty(prop);
    

    Then you can use the soapobject sp_Object for your parser.

提交回复
热议问题