How can I cast a String to a SoapObject in ksoap2?

前端 未结 3 958
既然无缘
既然无缘 2021-01-07 14:29

In my Android app I use ksoap2 for communication with a server. I download a certain complex sports information structure via soap request and parse it later in my program.<

3条回答
  •  醉话见心
    2021-01-07 14:42

    Hope this should work fine for converting a soap XML string to a SoapObject

    public SoapObject string2SoapObject(byte[] bytes)
    {
        SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER12);
        SoapObject soap=null;
        try {
            ByteArrayInputStream inputStream=new ByteArrayInputStream(bytes);
            XmlPullParser p= Xml.newPullParser();
            p.setInput(inputStream, "UTF8");
            envelope.parse(p);
            soap=(SoapObject)envelope.bodyIn;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return soap;
    }
    

提交回复
热议问题