2

I am trying to retrieve List of String from my SoapObject.I am using KSoap2 to call my webservice which returns List of Strings.Here is my code

SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

Can anybody help me to get all the list elements from my SoapPrimitive object.

like List abc =response.getList() or something??

3 Answers 3

1

Your case is a simplified version of this case: Parsing kSoap response to array of objects

But with a minor difference, your objects are simple:

SoapObject result = (SoapObject) envelope.getResponse();
SoapObject soapresults = (SoapObject)result.getProperty(0);

int count = soapresults.getPropertyCount();

ArrayList<PT> simplifiedList = new ArrayList<PT>(); 
for (int i = 0; i < count; i++)
{
     soapresults.getPropertyAs(PT)(i)
}
Sign up to request clarification or add additional context in comments.

8 Comments

This is what i have done..SoapObject result = (SoapObject)envelope.getResponse(); SoapObject soapResult = (SoapObject)result.getProperty(0); int count = result.getPropertyCount(); prjList = new ArrayList<String>(); for(int i=0;i<count;i++) { prjList.add(soapResult.getPropertyAsString(i)); }
Thanks for your response @Thunder-KC Inc...I tried your code but getting the following exception when I am setting my Spinner(Dropdown) with the value of above list element with this code.. intent.putStringArrayListExtra("projectListSpinner", simlifiedList); Exceptions 12-04 11:14:01.819: E/AndroidRuntime(552): FATAL EXCEPTION: main 12-04 11:14:01.819: E/AndroidRuntime(552): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.nevaeh.emsandroid/com.nevaeh.emsandroid.TourRequest}: java.lang.NullPointerException 12-04 11:14:01.819: E/AndroidRuntime(552): plz Help me Sir
is this list the list extracted from ksoap?
sir this list extracted from KSoap2-android-assembly-2.5.8
what I want to know is where exception occurred after filling list when you want to put it to intent or another time?
|
0

Finally got the answer with help of @Thunder 's suggestion Instead of
SoapObject result = (SoapObject) envelope.getResponse(); We have to use

java.util.Vector<String> result11 = (java.util.Vector<String>)envelope.getResponse(); // to get List of Strings from the SoapObject.. then
ArrayList<String> prjList = new ArrayList<String>();
for(String cs : result11)
{
prjList.add(cs);
}

Comments

0

You can get the strings of your soapObject like this:

SoapObject resSoap =(SoapObject)envelope.bodyIn; 
int count = resSoap.getPropertyCount();
for (int i=0; i<count;i++){
    SoapObject so = (SoapObject) resSoap.getProperty(i);
    int idxic = so.getPropertyCount();
    lst= new String[idxic];
    String item;
    for (int e=0; e<idxic;e++){
        item=so.getProperty(e).toString();
        lst[e]=item;
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.