org.xmlpull.v1.XmlPullParserException: неожиданный токен (позиция: TEXT {"Response": "Suc ... @ 1:50 в java.io.InputStreamReader@ab60c76) - PullRequest
0 голосов
/ 01 мая 2019

Метод, который я пытаюсь вызвать, успешно выполнен. Данные также хранятся на сервере.

Ответ в формате JSON:

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

Теперь я хочу сохранить ответ и ссылку. Нет результата, но когда я это делаю, androidHttpTransport.call (SOAP_ACTION1, envelope) выдает исключение 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();
            }
        }

    }
...