ksoap2我如何可以投一个字符串SoapObject? [英] ksoap2 How can I cast a String to a SoapObject?

查看:131
本文介绍了ksoap2我如何可以投一个字符串SoapObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Andr​​oid应用我使用kso​​ap2用于与服务器通信。我下载某些复杂的体育信息结构通过SOAP请求,后来在我的程序解析它。

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.

我想要做的就是以某种方式拯救这个复杂的结构,这样我可以稍后再分析它时,在该结构中的所有信息是终局的,不会再改变,这样我可以显示它而不调用Web服务试。

What I want to do is somehow "save" this complex structure so that I can parse it again later when all the information in that structure is final and doesn't change anymore so that I can display it without calling the web service again.

我那么远,我可以把整个结构转换成字符串从SoapObject类的toString()方法,这样我可以将它保存在应用程序的共享preferences。

I got that far that I can turn the whole structure into a string with the toString() method from the SoapObject class so that I can save it in the app's Shared preferences.

但是:为了解析字符串与我的解析器,我用我的时候直接从Web服务器,我需要它作为一个SoapObject下载数据。我想是这样的:

BUT: To parse the the string with my parser that I use when I download the data directly from the web server I need it as a SoapObject. I tried something like this:

SoapObject soapObj = (SoapObject) dataAsStringFromSharedPrefs;

但我不能投一个字符串SoapObject的方式。任何人都可以帮助我吗?

But I cannot cast a string to a SoapObject that way. Can anyone help me please?

在此先感谢, kaolick

Thanks in advance, kaolick

推荐答案

这这里似乎工作:

public SoapObject createSoapObjectFromSoapObjectString(String soapObjectString)
{
// Create a SoapSerializationEnvelope with some config
SoapSerializationEnvelope env = new SoapSerializationEnvelope(SoapEnvelope.VER11);
env.dotNet = true;

// Set your string as output
env.setOutputSoapObject(soapObjectString);

// Get response
SoapObject so = (SoapObject) env.getResponse();

return so;
}

这篇关于ksoap2我如何可以投一个字符串SoapObject?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆