到目前为止,我已经设法连接到一个Web服务并获得我的SoapObject响应,但是我无法缩小一个很好的,干净的解析方式。搜索互联网并没有真正产生太多的结果,每个人都有不同的方式和不同的流程,通常针对他们自己的Web服务,使其成为一次性使用类型的解决方案。基本上,下面是我从一个Web服务有没有更好的解析Android中的SoapObject的方法
anyType{
schema=anyType{
element=anyType{
complexType=anyType{
choice=anyType{
element=anyType{
complexType=anyType{
sequence=anyType{
element=anyType{};
element=anyType{};
element=anyType{};
element=anyType{}; }; }; }; }; }; }; };
diffgram=anyType{
NewDataSet=anyType{
Rep_x0020_Information=anyType{
Login=CorrectLogin; Password=InCorrectPass; }; }; }; }
,基本上我希望能够解析出刚刚在两个重要领域(登录名和密码)获得响应。从我阅读的内容来看,我试着迭代基于属性计数的SoapObject响应,但似乎并不奏效。当我想我得到的2财产计数响应所以不是我最后做一些这样的事如下:
SoapObject response=(SoapObject) envelope.getResponse();
if (response != null) {
Log.i("Message", "the response contains: " + response.toString());
SoapObject diffgram = (SoapObject) response.getProperty("diffgram");
SoapObject NewDataSet = (SoapObject) diffgram.getProperty("NewDataSet");
SoapObject RepInfo = (SoapObject) NewDataSet.getProperty("Rep_x0020_Information");
for (int i = 0; i < RepInfo.getPropertyCount(); i++) {
PropertyInfo info = new PropertyInfo();
RepInfo.getPropertyInfo(i, info);
Log.d("Info", info.name + " : " + RepInfo.getProperty(i).toString());
}
//which gives the following message in LogCat
D/Info(716): Login : InCorrectLogin
D/Info(716): Password : InCorrectPass
这个过程的作品,由最后一个循环,我得到了两个对象我想,但我只是觉得有一个更干净的方式来做到这一点。我只问,因为当我进一步进入这个应用程序时,会有一些更复杂的Web服务调用被创建,我希望能够在整个应用程序中拥有可重用的内容,而不必为每个请求构建多个SoapObjects直到我想要的物体。
我想,你可以使用JSONObject,json对解析非常简单 – Jamshid