O_Casper_ne 2012-12-07 09:33 采纳率: 7.7%
浏览 7727
已采纳

使用ksoap2传递字符串数组到webservice

在android程序中有一个Web Client使用ksoap2,但是还是不能把字符串数组作为一个参数传递到webservice中。
贴出相关代码:

String[] items={"hello","world"};
request.addproperty("str",items);

请求大家的帮忙,谢谢!

  • 写回答

3条回答 默认 最新

  • franzhong 2012-12-08 05:37
    关注

    好像只能一条条加

    public class ExtendedSoapObject extends SoapObject
    {
        public ExtendedSoapObject(String namespace, String name)
        {
            super(namespace, name);
        }
    
        public ExtendedSoapObject(SoapObject o)
        {
            super(o.getNamespace(), o.getName());
            for (int i = 0; i < o.getAttributeCount(); i++)
            {
                AttributeInfo ai = new AttributeInfo();
                o.getAttributeInfo(i, ai);
                ai.setValue(o.getAttribute(i));
                addAttribute(ai);
            }
    
            for (int i = 0; i < o.getPropertyCount(); i++)
            {
                PropertyInfo pi = new PropertyInfo();
                o.getPropertyInfo(i, pi);
                pi.setValue(o.getProperty(i));
                addProperty(pi);
            }
        }
    
    
        @Override
        public SoapObject addProperty(String name, Object value)
        {
            if (value instanceof Object[])
            {
                Object[] subValues = (Object[]) value;
                for (int i = 0; i < subValues.length; i++)
                {
                    super.addProperty(name, subValues[i]);
                }
            }
            else
            {
                super.addProperty(name, value);
            }
    
            return this;
        }
    
    
        @Override
        public Object getProperty(String name)
        {
            List<Object> result = new ArrayList<Object>();
    
            for (int i = 0; i < properties.size(); i++)
            {
                PropertyInfo prop = (PropertyInfo) properties.elementAt(i);
                if (prop.getName() != null && prop.getName().equals(name))
                {
                    result.add(unwrap(prop));
                }
            }
    
            if (result.size() == 1)
            {
                return result.get(0);
            }
            else if (result.size() > 1)
            {
                return result.toArray(new Object[0]);
            }
            else
            {
                return null;
            }
        }
    
        public Object[] getArrayProperty(String name)
        {
            Object o = getProperty(name);
            Object values[] = null;
            if (o != null)
            {
                if (o instanceof Object[])
                {
                    values = (Object[]) o;
                }
                else
                {
                    values = new Object[1];
                    values[0] = o;
                }
            }
    
            return values;
        }
    
        Object unwrap(Object o)
        {
            if (o instanceof PropertyInfo)
            {
                return unwrap(((PropertyInfo) o).getValue());
            }
            else if (o instanceof SoapPrimitive || o instanceof SoapObject)
            {
                return o;
            }
    
            return null;
        }
    }
    

    不知此类对你是否有参考价值

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器