用Java 在 KSOAP中序列化复杂对象数组实体_第1张图片

1:实体类SQueEnt

复制代码

public class SQueEntimplements KvmSerializable {

 

    // 标题,内容,类型数组

    private String lblText;

    private String txtText;

    private String Type;

    public SQueEnt(){}

    public SQueEnt(String lblText, String txtText, String Type) {

       this.lblText = lblText;

       this.txtText = txtText;

       this.Type = Type;

    }

    @Override

    public Object getProperty(int arg0) {

       switch (arg0) {

       case 0:

           return lblText;

       case 1:

           return txtText;

       case 2:

           return Type;

       }

       return null;

    }

    @Override

    public int getPropertyCount() {

       return 3;

    }

    @Override

    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfoarg2) {

       // arg2.namespace =WebService.NAMESPACE;

       switch (arg0) {

       case 0:

           arg2.type = PropertyInfo.STRING_CLASS;

           arg2.name = "lblText";

           break;

       case 1:

           arg2.type = PropertyInfo.STRING_CLASS;

           arg2.name = "txtText";

           break;

       case 2:

           arg2.type = PropertyInfo.STRING_CLASS;

           arg2.name = "Type";

           break;

       default:

           break;

       }

    }

    @Override

    public void setProperty(int arg0, Object arg1) {

       switch (arg0) {

       case 0:

           lblText = arg1.toString();

       case 1:

           txtText = arg1.toString();

       case 2:

           Type = arg1.toString();

       }

    }

}

复制代码

2:实体数组ArrayOfSQueEnt

复制代码
    

public class ArrayOfSQueEnt  extends Vector implements KvmSerializable {

    private static final long serialVersionUID = -1166006770093411055L;

    @Override

    public Object getProperty(int arg0) {

            return this.get(arg0);

    }

    @Override

    public int getPropertyCount() {

            return this.size();

    }

    @Override

    public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfoarg2) {

            arg2.name = "SQueEnt";

            arg2.type = SQueEnt.class;

    }

    @Override

    public void setProperty(int arg0, Object arg1) {

            this.add((SQueEnt)arg1);

    }

}

复制代码

3:webservices上传

复制代码

    public static final String NAMESPACE ="http://tempuri.org/";

    private static final String URLCatalog ="http://192.168.1.123:8002/AssetServer/CatalogService.asmx";

    private static final String URLCount ="http://192.168.1.123:8002/AssetServer/AccountService.asmx";

    private static final String URLFile ="http://192.168.1.123:8002/AssetServer/FileService.asmx";

    private static final String URLQuery ="http://192.168.1.123:8002/AssetServer/QueryService.asmx";

    private static final String URLWork ="http://192.168.1.123:8002//AssetServer/WorkFlowService.asmx";

    SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(

           SoapEnvelope.VER11);


具体的方法如下:
    

public void fillTable(String id) {

       String method = "fillTableByID";

       SQueEnt sqe = new SQueEnt("磁带编号,并列正题名", "后台测试", "nvarchar(50)");

       ArrayOfSQueEnt sci = new ArrayOfSQueEnt();

       sci.add(sqe);

       sci.add(sqe);

       SoapObject request = new SoapObject(NAMESPACE, method);

       PropertyInfo tabProp1 = new PropertyInfo();

       tabProp1.setName("sqecol");

       tabProp1.setValue(sci);

       tabProp1.setType(ArrayOfSQueEnt.class);

       request.addProperty(tabProp1);

       // String id="179d570d-5da3-40ac-a7ba-e72c02c38b4c";

       // request.addProperty("sqecol",array);

       String type = getFiletype(id);

       request.addProperty("xbType", type);

       request.addProperty("Fileid", id);

       //System.out.println(type +"  :" + id);

       envelope.addMapping(NAMESPACE, "sqecol",

              new ArrayOfSQueEnt().getClass());

       envelope.addMapping(NAMESPACE, "SQueEnt", new SQueEnt().getClass());

       envelope.bodyOut = request;

       envelope.dotNet = true;

       envelope.setOutputSoapObject(request);

       envelope.encodingStyle = "UTF-8";

       HttpTransportSE androidHttpTransport = new HttpTransportSE(URLQuery);

       androidHttpTransport.debug = true;

       try {

           androidHttpTransport.call(NAMESPACE + method, envelope);

           if (envelope.bodyIn != null) {

              Object resultObj = (Object) envelope.bodyIn;

              System.out.println(envelope.bodyIn.toString());

           } else {

              System.out.println("WebServicefillTable()没有获取到数据!");

           }

       } catch (IOException e) {

           System.out.println(e);

           e.printStackTrace();

       } catch (XmlPullParserException e) {

           System.out.println(e);

           e.printStackTrace();

       }

    }

复制代码 参考: https://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#Manual_Parsing_of_an_Array_of_into_an_POJO_array

更多相关文章

  1. 可分享到 Android、iOS 和 Flutter平台的Rust代码编译 [转]
  2. Android拍照上传功能示例代码
  3. Android DEX反编译后部分代码解析
  4. android: 大量开源项目源代码分享
  5. android重启代码
  6. android 发布正式版时用Gradle移除日志打印代码(添加混淆配置)
  7. [置顶] android studio 如何进行格式化代码 快捷键必备

随机推荐

  1. android IPlog的抓取方法
  2. Android 学生管理系统 之 SQLite数据库操
  3. Android 开源框架Universal-Image-Loader
  4. Android Freeform模式
  5. 推荐几款比较好Android视频播放器
  6. Androidx和Android support库共存时问题:a
  7. android程序退出当前activity的方法
  8. Android自定义属性 及 TypedArray的使用
  9. Android SDK中tools下工具详解
  10. 多字文本android:ellipsize不正常工作的