org.xmlpull.v1.XmlPullParserException:意外的令牌(位置:TEXT {“ Response”:“ Suc ... @ 1:50在java.io.InputStreamReader@ab60c76中)

时间:2019-05-01 11:51:59

标签: java android web-services wsdl android-ksoap2

我尝试调用的方法已成功执行。数据也存储在服务器中。

响应采用JSON格式:

{
  "Response": "Success",
  "ReferenceNo": "2019-05-26"
}

现在我想存储响应和referenceNo结果,但是当我这样做时androidHttpTransport.call(SOAP_ACTION1,信封)抛出XmlPullParserException。

org.xmlpull.v1.XmlPullParserException:意外的令牌(位置:TEXT {“ Response”:“ Suc ... @ 1:50在java.io.InputStreamReader@715cfa1中)

您看到的响应已成功存储,但由于异常而无法捕获结果。

private class SetTreasureBoxAsyncTask extends AsyncTask<String, String, String>
    {

        @Override
        protected void onPreExecute() {
            super.onPreExecute();
        }
        @Override
        protected String doInBackground(String... params) {

            //Initialize soap request + add parameters
            SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME1);
            //Use this to add parameters
            request.addProperty("Request",task);
            //Declare the version of the SOAP request
            SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
            envelope.setOutputSoapObject(request);
            envelope.dotNet = true;
            try {
                HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
                //this is the actual part that will call the webservice
                androidHttpTransport.call(SOAP_ACTION1, envelope);
                // Get the SoapResult from the envelope body.
//
                SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
                String responseJSON=response.toString();
                JSONArray jarray =new JSONArray(responseJSON);

                String result = jarray.getJSONObject(0).getString("Response");

                return result;

            }catch (Exception e){
                e.printStackTrace();
                return null;
            }
            }

        @Override
        protected void onPostExecute(String result) {
            super.onPostExecute(result);
            if(result != null)
            {
                Toast.makeText(Form.this, "Result: "+result, Toast.LENGTH_SHORT).show();
            }
            else
            {
                Toast.makeText(getApplicationContext(), "No Response", Toast.LENGTH_LONG).show();
            }
        }

    }

0 个答案:

没有答案