Research Development
Research Development

Reputation: 904

how to parse data from Soap envelope object in android

SoapObject result = (SoapObject) envelope.getResponse();
SoapObject root = (SoapObject) result.getProperty(0);
SoapObject s_deals = (SoapObject) root.getProperty("InfraWiseDetails");
SoapObject s_deals_1 = (SoapObject) s_deals.getProperty("VisitInfraDetails");

for (int i = 0; i < s_deals_1.getPropertyCount(); i++) {
    Object property = s_deals_1.getProperty(i);

    if (property instanceof SoapObject) {
        SoapObject category_list = (SoapObject) property;
        String x = category_list.getProperty("Feedback").toString();
        String y = category_list.getProperty("InfraName").toString();
        String z = category_list.getProperty("Problem").toString();
    }
}

this is my Code

in SoapObject SoapObject result = (SoapObject) envelope.getResponse(); i am getting response --->

anyType{InfraWiseDetails=anyType{VisitInfraDetails=anyType{Feedback=Status OK; InfraName=Tables and Chairs; Problem=null; ResolutionStatus=false; Status=true; };

VisitInfraDetails=anyType{Feedback=Water Quality very poor; InfraName=Water; Problem=Rust in Water; ResolutionStatus=false; Status=false; }; }; VisitMasterId=1; }

I want to Parse data from given SoapObject and get all value of FeedBack, Infraname, Problem... please tell me where am doing wrong i am unable to get value

Upvotes: 1

Views: 3178

Answers (2)

SANAT
SANAT

Reputation: 9257

After long time i am looking on ksoap2 code. Try this :

SoapObject result = (SoapObject) envelope.getResponse();
SoapObject root = (SoapObject) result.getProperty(0);
SoapObject s_deals = (SoapObject) root.getProperty("InfraWiseDetails");

for (int i = 0; i < s_deals.getPropertyCount(); i++) {
    SoapObject s_deals_1 = (SoapObject) s_deals.getProperty(i);
    String x = s_deals_1.getProperty("Feedback").toString();
    String y = s_deals_1.getProperty("InfraName").toString();
    String z = s_deals_1.getProperty("Problem").toString();   
}

Upvotes: 3

Android Dev
Android Dev

Reputation: 433

Try like this in your Code , You can parse the data from KSoap

getdata(String SearchValue)- Call this method inside your do inBackground

public void getdata(String SearchValue) 
        {
            // Create request
            SoapObject request = new SoapObject(NAMESPACE2, METHOD_NAME2);



            PropertyInfo pi4 = new PropertyInfo();
            pi4.setName("City");
            pi4.setValue(SearchValue);// get the string that is to be sent to the webservice
            pi4.setType(String.class);
            request.addProperty(pi4);

            // Create envelope
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.dotNet = true;
            // Set output SOAP object
            envelope.setOutputSoapObject(request);
            // Create HTTP call object
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL2);

            try {
                // Invole web service
                androidHttpTransport.call(SOAP_ACTION2, envelope);
                // Get the response
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();

                //Converting string to Array list
                  ArrayList<String> Servciecityname_arr= new ArrayList<String>();


                if ((response.toString()).contains("{")) 
                {

                    SoapObject rep = (SoapObject) envelope.bodyIn;
                    JSONArray jr = new JSONArray(rep.getPropertyAsString(0));
                    for (int i = 0; i < jr.length(); i++) {
                        JSONObject jb = (JSONObject) jr.get(i);


                           Cityname = jb.getString("CityName123");


                           Servciecityname_arr.add(Cityname);

                    }

                    CITYNAME = new String[Servciecityname_arr.size()];
                    CITYNAME = Servciecityname_arr.toArray(CITYNAME);


                } 
                else
                {
                    Status_Response = response.toString();
                }

            } catch (Exception e) {
                Log.i(TAG2, "Error in catch");
                e.printStackTrace();
            }

        }

Upvotes: 0

Related Questions