Android:从字符串构造SoapObject

时间:2016-02-17 04:30:26

标签: android

在我的一个Android项目中,我使用了ksoap2库来使用soap web服务。我需要预先加载一些可在用户离线时用于显示的数据。为此,我曾经将soap web服务的响应存储为SQLite数据库作为字符串。我需要找到一种从存储在sqlite数据库中的String重构SoapObject(响应对象)的方法。

我尝试了以下页面中提到的已批准的解决方案,方法是将先前保存的数据库中的响应字符串传递给方法createSoapObjectFromSoapObjectString()。它会抛出异常,因为env.getResponse()为空。

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

我还尝试通过调用以下语句将数据库中先前保存的响应字符串直接转换为SoapObject,但它也会抛出ClassCastException异常

SoapObject so = (SoapObject) (Object) soapObjectString;

以下是我想从中构造SoapObject的示例响应字符串。 ()

anyType{PatientGroupDetailDC=anyType{HasOverDueTask=No; HasUpComingTask=No; PatientReferenceNo=13; PatientName=02dvwZq8cMhx3bCH96iSMA==; NRICNumber=Gk1dfdkzJAvLJifFdBh2XA4aA==;}; PatientGroupDetailDC=anyType{HasOverDueTask=No; HasUpComingTask=No; PatientReferenceNo=TP00212011; PatientName=5OerjU0weryq/rcPR1QkxlEg==; NRICNumber=d3gFkmVkJqbGdMaO6efdVkIcQ==;}; }

1 个答案:

答案 0 :(得分:-1)

试试这段代码,

SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        Object retObj = soapEnvelope.bodyIn; //OR// Object retObj = "your string response from database";
        SoapObject result = (SoapObject) retObj;
        if (result.getPropertyCount() > 0) {
            Object obj = result.getProperty(0);
        }