gpt4 book ai didi

java - 使用 KSOAP2 序列化要发送的整数数组

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:56:05 24 4
gpt4 key购买 nike

我在尝试将整数数组发送到 .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);

生产

 <classificationIds>
<n4:short i:type="d:long" xmlns:n4="http://schemas.microsoft.com/2003/10/Serialization/Arrays">18</n4:short>
</classificationIds>

看起来很糟糕,但服务器还是吃了它

关于java - 使用 KSOAP2 序列化要发送的整数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4951333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com