无法在android

时间:2016-12-01 14:43:23

标签: android xml soap

这些是如何使用这些标记从服务器获取响应的XML标记。

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <GetTimeSheet xmlns="http://tempuri.org/">
      <ObjTse>
        <FromDate>2016-11-01</FromDate>
        <ToDate>2016-11-26</ToDate>
        <UserID>df7583a54a3</UserID>
        <InvoiceMode></InvoiceMode>
        <Status></Status>
        <TransType>TimeSheet</TransType>
      </ObjTse>
    </GetTimeSheet>
    </soap:Body>
</soap:Envelope>

我在doInBackground方法中编写的代码

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

        try
        {
            SoapObject  Request = new SoapObject(NAMESPACE, METHOD_NAME);
            PropertyInfo pp = new PropertyInfo();
             pp.setName("ObjTse");


            Request.addProperty("FromDate", "2016-11-01");
            Request.addProperty("ToDate", "2016-11-26");
            Request.addProperty("UserID", "d458183a5-ha4812tg");
            Request.addProperty("InvoiceMode","All");
            Request.addProperty("Status", "");
            Request.addProperty("TransType", "TimeSheet");
            Request.addProperty(pp);
            pp.setElementType(pp);


            SoapSerializationEnvelope soapEnvelope = new                     
            SoapSerializationEnvelope(SoapEnvelope.VER11);
            soapEnvelope.dotNet = true;
            soapEnvelope.implicitTypes = true;
            soapEnvelope.setAddAdornments(false);
            soapEnvelope.setOutputSoapObject(Request);

            HttpTransportSE transport = new HttpTransportSE(URL);
            transport.setXmlVersionTag("<?xml version=\"1.0\" 
            encoding=\"utf-8\"?>");
            transport.debug = true;
            transport.call(SOAP_ACTION, soapEnvelope);

            xmlString = transport.responseDump;

            String result = soapEnvelope.getResponse().toString();

            try {
                JSONObject jsonObj = XML.toJSONObject(result);
                System.out.println("JJJJJJ==>>"+jsonObj);
            } catch (JSONException e) {
                Log.e("JSON exception", e.getMessage());
                e.printStackTrace();
            }


            xmlString = xmlString.replaceAll("&lt;", "<");
            xmlString = xmlString.replaceAll("&gt;", ">");

            System.out.println("GGGGG1==>>"+xmlString);
            System.out.println("BBBB!==>>"+result);

            resultString = (SoapPrimitive) soapEnvelope.getResponse();

            SoapObject resultBody = (SoapObject) soapEnvelope.bodyIn;
                    System.out.println("UUUUU==>>"+resultBody);



             } catch (Exception ex) {
            Log.e(TAG, "Error: " + ex.getMessage());
          }
            return null;
       }

只能获得第一个标签而不是元素

获取空的JSON值

无法找到返回空JSON数组的原因

0 个答案:

没有答案