Skip to content Skip to sidebar Skip to footer

Android Parse Object KSOAP

I'd like to know how do I parse the output of SOAP. My current code is the following: try{ SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); SoapSerializationEnv

Solution 1:

From your comments you need to parse the json array.

 JSONArray jr = new JSONArray("jsonstring");
 for(int i =0 ; i< jr.length();i++)
 {
 JSONObject jb =(JSONObject) jr.get(i);  
 String categoryid = jb.getString("category_id");
 String parent_id = jb.getString("parent_id");
 String name = jb.getString("name");
 }

Solution 2:

Solved thanks to @Raghunandan. Also, it retrieves the right encoding, which is awesome, since that json_encode put special characters on strings.

try{
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request);
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.call(SOAP_ACTION, envelope);

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

         String name = jb.getString("name");
         Log.e("value:", name);
     }

}catch (Exception e){
    Log.e("Error:", e.toString());
}

Post a Comment for "Android Parse Object KSOAP"