首页 > 代码库 > webservice返回SoapSerializationEnvelope在android端解析问题

webservice返回SoapSerializationEnvelope在android端解析问题

一般情况下:

SoapObject soapObject = (SoapObject) envelope.getResponse();

SoapObject detail = (SoapObject) envelope.getResponse();

                        for (int i = 0; i < detail.getPropertyCount(); i++) {       
                              SoapObject mstr = (SoapObject) detail.getProperty(i);
                              String str_result  = mstr.getProperty(0).toString();
                        }


但这种方法往往会产生java.lang.ClassCastException: 

org.ksoap2.serialization.SoapPrimitive这样的错误。


 应该

Object soapObject = 

(Object) envelope.getResponse();

或者

SoapPrimitive soapObject = 

(SoapPrimitive) envelope.getResponse();

然后再对获得的内容进行解析(不能再使用detail.getProperty(i)解析了,SoapPrimitive没有这个函数)




webservice返回SoapSerializationEnvelope在android端解析问题