如何在android中解析Soap响应中的数据

时间:2015-08-07 04:17:14

标签: android soap

SaveVisitInfraDetailJsonResponse{SaveVisitInfraDetailJsonResult=true; }我从服务器获取此响应

    SoapObject result = (SoapObject) envelope.bodyIn;
        SoapObject NewDataSet = (SoapObject) result
                .getProperty("SaveVisitInfraDetailJsonResult");
         for(int i=0;i<NewDataSet.getPropertyCount();i++)
            {
                if(result.getProperty(i) instanceof SoapObject)
                {               
                 String response =   (String)result.getProperty(i);
                }
                else
                {               
                    //do something with the current property

                    //get the current property name:
                    PropertyInfo pi = new PropertyInfo();
                    result.getPropertyInfo(i,pi);
                    String name = pi.getName();
                }
            }

使用上面的代码我试图获得SaveVisitInfraDetailJsonResult的值,但我无法获得该值。代码在SoapObject NewDataSet = (SoapObject) result处终止。请告诉我我做错了什么。

1 个答案:

答案 0 :(得分:1)

请尝试此代码并获取响应值 -

          try {

                SoapObject objSaveVisitInfraDetails = new SoapObject(NAMESPACE, PostMETHOD_NAME);
                JSONArray jsonArr = new JSONArray();
                JSONObject pnObj = new JSONObject();
                Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                bmp.compress(Bitmap.CompressFormat.JPEG, 40, stream);
                byte[] byteArray = stream.toByteArray();
                base64String = Base64.encode(byteArray,Base64.DEFAULT);
                for (int i = 0; i < 2; i++) {
                    pnObj.put("Feedback", "hello Mohit u are getting data ,Panday is karcha karoge?");
                    pnObj.put("InfraId", Integer.parseInt("1"));
                    pnObj.put("ResolveStatus", Boolean.valueOf("true"));
                    pnObj.put("VisitDetailId", Integer.parseInt("1"));
                    pnObj.put("Visit_MasterId", Integer.parseInt("1"));
                    jsonArr.put(pnObj);

                }

                objSaveVisitInfraDetails.addProperty("jsonString", jsonArr.toString());
                objSaveVisitInfraDetails.addProperty("VisitMasterId", 1);

                objSaveVisitInfraDetails.addProperty("dicImage", null);

                envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
                envelope.dotNet = true;
                envelope.setOutputSoapObject(objSaveVisitInfraDetails);

                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                androidHttpTransport.debug = true;

                androidHttpTransport.call(PostSOAP_ACTION, envelope);
                Log.d("Request ", androidHttpTransport.requestDump);
                Log.d("Response ", androidHttpTransport.responseDump);
                SoapObject result = (SoapObject) envelope.bodyIn; 
                int count=result.getPropertyCount();
                System.out.println("Result Count "+count);
                System.out.println("Result "+result.getProperty(0));
                if (result.hasProperty("SaveVisitInfraDetailJsonResult")) { 
                String string=result.getProperty(0).toString();
                System.out.println("Response Result: "+string);
                System.out.println("Response Result: "+result.getProperty(0));
            }
            } catch (SoapFault e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (XmlPullParserException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            catch (NullPointerException e) {
                // TODO: handle exception
                Log.d("Errorrr", e.getMessage());

                System.out.println(e.getMessage());
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }