如何解决XmlPullParserException?

时间:2018-05-17 04:48:08

标签: soap ksoap2

我从使用SOAP的api获取数据时遇到此异常。 我得到的响应是Json格式,没有xml标记。我还尝试使用HttpResponse解析数据,但它无法正常工作......

W/System.err: org.xmlpull.v1.XmlPullParserException: Unexpected token (position:TEXT {
  "Flag": 1,
 ...@6:2 in java.io.InputStreamReader@57e26d2) 
    at org.kxml2.io.KXmlParser.next(KXmlParser.java:432)
    at org.kxml2.io.KXmlParser.next(KXmlParser.java:313)
    at org.kxml2.io.KXmlParser.nextTag(KXmlParser.java:2048)
    at org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:126)
    at org.ksoap2.transport.Transport.parseResponse(Transport.java:63)
    at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:100)
    at com.kritilims.kritilimsfieldtesting.MainLoginActivity$UserLoginTask.doInBackground(MainLoginActivity.java:224)
    at com.kritilims.kritilimsfieldtesting.MainLoginActivity$UserLoginTask.doInBackground(MainLoginActivity.java:176)
    at android.os.AsyncTask$2.call(AsyncTask.java:295)
    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:234)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
    at java.lang.Thread.run(Thread.java:818)

这是我在asyncTask doInBackground中的代码。我不知道出了什么问题。错误发生在HttpTransportSe部分。

 @Override
    protected String doInBackground(String... params) {


        SoapObject request=new SoapObject(SOAP_NAMESPACE,SOAP_METHOD);
        request.addProperty("labcode",mLabCode.getText().toString());
        request.addProperty("username", mUserName.getText().toString());
        request.addProperty("pass",mPasswordView.getText().toString());

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

        try {

            HttpTransportSE androidHttpTransportSE=new HttpTransportSE(URL);
            androidHttpTransportSE.call(SOAP_ACTION,envelope);

            SoapPrimitive soapPrimitive=(SoapPrimitive)envelope.getResponse();
            result=soapPrimitive.toString();
            Log.e("Test Result",""+result);

            try {
                JSONArray jsonArray=new JSONArray(result);
                JSONObject jsonObject=jsonArray.getJSONObject(0);
                strStatusID=jsonObject.getString("Flag");
                labCode=jsonObject.getString("LabCode");
                userName=jsonObject.getString("Username");

                Log.e("Flag",""+strStatusID);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    } 

0 个答案:

没有答案