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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!