ClassCastException异常:SoapPrimitive不能转换到SoapObject(显然没有SoapPrimitive这里) [英] ClassCastException: SoapPrimitive can't be cast to SoapObject (Apparently there is no SoapPrimitive here)

查看:517
本文介绍了ClassCastException异常:SoapPrimitive不能转换到SoapObject(显然没有SoapPrimitive这里)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我耗费了基于SOAP的Web服务使用 ksoap2 ,并接收从WebService,这是我在 SoapObject 正在存储JSON响应

I am consuming a SOAP based web-service using ksoap2, and receiving a JSON response from the webservice, which I am storing in a SoapObject.

接下来的步骤是的解析<​​code> JSON 的。对于我试图从响应SoapObject获得每个属性并将其存储在另一个 SoapObject ,进行进一步的处理(像获得名称等)

The next step is to parse the JSON. For that I am trying to get each property from the response SoapObject and store it in another SoapObject, for further processing (like getting the name and value etc.)

SoapObject soapObjectEach= (SoapObject) postResult.getProperty(i); 

但我在这个声明得到一个例外 java.lang.ClassCastException:org.ksoap2.serialization.SoapPrimitive不能转换为org.ksoap2.serialization.SoapObject

postResult是SoapOject。这说明我postResult.getProperty()可能会返回一个SoapPrimitive?但我几乎可以肯定,这是不是这种情况,作为<一个href=\"http://kobjects.org/ksoap2/doc/api/org/ksoap2/serialization/SoapObject.html#getProperty%28int%29\"相对=nofollow>文档说,返回所需属性

postResult is a SoapOject. This suggests me that postResult.getProperty() probably returns a SoapPrimitive? But I am almost certain that it is not the case, as the documentation says, "Returns the desired property"

所以任何人可以提出关于它的东西吗?我已经看到了这个其他问题(<一个href=\"http://stackoverflow.com/questions/18892434/java-lang-classcastexception-org-ksoap2-serialization-soapprimitive-cannot-be-c\">1, <一href=\"http://stackoverflow.com/questions/23220502/org-ksoap2-serialization-soapobject-cannot-be-cast-to-org-ksoap2-serialization-s\">2)但没有得到一个满意的答案。

So can anybody suggest something about it? I have seen other questions about this (1, 2) but did not get to a satisfactory answer.

推荐答案

让您diagonize code:

Lets diagonize your code:

SoapObject soapObjectEach= (SoapObject) postResult.getProperty(i); 

至于你说postResult是soapobject。而从上的getProperty文件说:

As you said postResult is a soapobject. And from the documentation on getproperty says:

getProperty

public java.lang.Object getProperty(int index)
Returns a specific property at a certain index.
Specified by:
getProperty in interface KvmSerializable
Parameters:
index - the index of the desired property
Returns:
the desired property

使用getProperty返回的指数,而不是一朝一夕所能始终被铸造成soapobject财产。从你的异常,我们可以看到它返回类型soapprimitive的对象。因此,解决方案是类似的东西<一个href=\"http://stackoverflow.com/questions/5799775/ksoap2-android-cast-class-exception-soapobject\">this帖子。

这篇关于ClassCastException异常:SoapPrimitive不能转换到SoapObject(显然没有SoapPrimitive这里)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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