如何在ksoap2中将字符串强制转换为SoapObject? [英] How can I cast a String to a SoapObject in ksoap2?

查看:127
本文介绍了如何在ksoap2中将字符串强制转换为SoapObject?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Android应用中,我使用kso​​ap2与服务器进行通信.我通过肥皂请求下载了某种复杂的体育信息结构,并在以后的程序中对其进行了解析.

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()方法将整个结构转换为字符串,以便将其保存在应用程序的共享"首选项中.

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.

推荐答案

在这里似乎可行:

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天全站免登陆