我在尝试将整数数组发送到 .NET Web 服务时遇到问题,该服务需要参数之一包含数组。至少这是我从 Web 服务上的 API 描述中了解到的:
<dataIndexIDs>
<int>int</int>
<int>int</int> </dataIndexIDs>
因此,当我发送如下所示的单个 int 时,我不会收到任何错误,并且我认为它工作正常。
request.addProperty("dataIndexIDs", 63);
但是当我尝试发送整数数组时:
request.addProperty("dataIndexIDs", new int[] {63, 62}); // array of ints
或整数数组列表:
ArrayList<Integer> indexes = new ArrayList<Integer>();
indexes.add(63);
indexes.add(62);
request.addProperty("dataIndexIDs", indexes); // ArrayList of Integers
我抛出“java.lang.RuntimeException:无法序列化”异常。有什么帮助吗?我究竟做错了什么?谢谢!
我从 Android 客户端发送到 .NET 服务器,这对我有用
SoapObject myArrayParameter = new SoapObject(NAMESPACE, MY_ARRAY_PARAM_NAME);
for( int i : myArray ) {
PropertyInfo p = new PropertyInfo();
p.setNamespace("http://schemas.microsoft.com/2003/10/Serialization/Arrays");
// use whatever type the server is expecting here (eg. "int")
p.setName("short");
p.setValue(i);
myArrayParameter.addProperty(p);
}
request.addSoapObject(myArrayParameter);
Produces
<classificationIds>
<n4:short i:type="d:long" xmlns:n4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">18</n4:short>
</classificationIds>
看起来很糟糕,但服务员还是把它吃掉了
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)