user1901079
user1901079

Reputation: 447

Parsing ksoap2 Object in android

I am getting a soap response like this.....

anyType{ViewList=anyType{View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB5L2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB5L1; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB4; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB2L2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB6; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB6L2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB7L2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB7L3; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB7L4; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB8L1; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB8L2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB8L3; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB8L4; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB8L5; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB9L1; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB9L2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB9L3; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB10L1; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB10L2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=dbpdftest2; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDBT1; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=anyType{}; ViewName=pdfDB7L1; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=myView; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=pdfDB5L3; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=anyType{}; ViewName=pdfDM13L1; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=anyType{}; ViewName=pdfDM15L1; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=anyType{}; ViewName=pdfM15; response=anyType{}; visibility=Assigned To; }; View=anyType{ViewList=null; ViewID=1; ViewName=MandS; response=anyType{}; visibility=Assigned To; }; }; ViewID=null; ViewName=null; response=anyType{ResponseStatus=SUCCESS; }; visibility=null; }

I am trying getting this from this request....

try {
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            androidHttpTransport.call(SOAP_ACTION, envelope);

            SoapObject result = (SoapObject) envelope.getResponse();

            if (result != null) {
                System.out.println(result);
                //userIsValid = parseResponse(result);
                return result;
            } else {
                Toast.makeText(getApplicationContext(), "No Response",
                        Toast.LENGTH_LONG).show();
                return null;
            }
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

And parsing the soap object like this....

private boolean parseResponse(SoapObject root) {
        // TODO Auto-generated method stub

        for (int i = 0; i < root.getPropertyCount(); i++) {

            Object property = root.getProperty(i);
            if (property instanceof SoapObject) {
                SoapObject category_list = (SoapObject) property;

                if (category_list.hasProperty("ResponseStatus")) {
                    System.out.println(category_list.getProperty("dashboardName").toString());

                //}

            }

        }

        return true;

    }

But here I only get the response as Success...I want to access all the values there such as ViewName,view id etc..how can I do that..

Upvotes: 0

Views: 309

Answers (2)

Kalai.G
Kalai.G

Reputation: 1610

Try to parse that soapobject and store it in vector.

This Code Snippet may help you,

public static Vector parsealldetails(SoapObject resultObject) {
    Vector predictionList = new Vector();
    SoapObject resObject = (SoapObject) (resultObject).getProperty(0);

    String[][] HAll = new String[0][2];

    for (int i = 0; i < resObject.getPropertyCount(); i++) {
        HAll = expand(HAll, i + 1, 4);
        int j = 0;

        while (j < 2) {
            j++;
            String str1 = ((SoapObject) resObject.getProperty(i))
                    .getProperty("ID").toString();
            HAll[i][j - 1] = str1;

            j++;
            String str2 = ((SoapObject) resObject.getProperty(i))
                    .getProperty("Name").toString();
            HAll[i][j - 1] = str2;

        }
    }

    predictionList.addElement(HAll);
    return predictionList;
}

and if you use boolean, it will brings out the result as success or failure only

Upvotes: 1

Pradip
Pradip

Reputation: 3177

If you are looking for array of complexType as areturn from KSOAP, then please take a look here.

Upvotes: 0

Related Questions