Web服务- ksoap2-android序列化一个空数组



我想使用ksoap2创建一个对象Group,其中包含一个空列表。我设法做到这一点独立应用程序使用webservice方法,但是,使用android给了我一个错误:java.lang.RuntimeException: Cannot serialize: []我的问题,是否有一个步行到这个错误?

这是我的WSDL xml:

<xs:complexType name="createGroup">
<xs:sequence>
<xs:element name="new-group-object" type="tns:group" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="group">
<xs:sequence>
<xs:element name="groupId" type="xs:long"/>
<xs:element name="groupName" type="xs:string" minOccurs="0"/>
<xs:element name="users" type="tns:user" nillable="true" minOccurs="0" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="user">
<xs:sequence>
<xs:element name="latitude" type="xs:double"/>
<xs:element name="longitude" type="xs:double"/>
<xs:element name="userAge" type="xs:int"/>
<xs:element name="userId" type="xs:long"/>
<xs:element name="userName" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>

和我的android客户端方法:

public void createGroupServ(String groupName) 
{
    request = new SoapObject(NAMESPACE, "createGroup");
    SoapObject soapGroup = new SoapObject(NAMESPACE, "group");
    Group gr = new Group();
    gr.setGroupName(groupName);
    gr.setUsers(new ArrayList<User>());
    request.addProperty("new-group-object", gr);
    envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.dotNet = false;
    envelope.setOutputSoapObject(request);
    androidHttpTransport = new HttpTransportSE(URL);
    androidHttpTransport.debug = true;
      ... 
    }

需要为组和用户实现KvmSerializable接口。阅读以下文章:java.lang.RuntimeException: Cannot serialize: MyClass

http://www.sgoliver.net/blog/?p=2594

我建议升级到最新版本的ksoap,因为你可能不得不使用:http://seesharpgears.blogspot.com/2010/11/implementing-ksoap-marshal-interface.html对于双数据类型

最新更新