type
  TRespparms = class(TPersistent)
  private
    Fjlbh: Integer;
    FbNeedQuery: Boolean; //是否需要调用查询接口
    FsMsg: string; //
    FsOrderNO: string; //请求的订单号
    FiTotal_fee: Integer; //
    FsTransaction_id: string; //--终端流水号
    FsBankName: string; //----银行号
    FiChannel: Integer; //----渠道号
    FsBankType: string; //---银行接口类型 
    FiJYLX: Integer; //-----
  published
    property bNeedQuery: Boolean read FbNeedQuery write FbNeedQuery;
    property sMsg: string read FsMsg write FsMsg;
    property sOrderNO: string read FsOrderNO write FsOrderNO;
    property iTotal_fee: Integer read FiTotal_fee write FiTotal_fee;
    property sTransaction_id: string read FsTransaction_id write FsTransaction_id;
    property sBankName: string read FsBankName write FsBankName;
    property iChannel: Integer read FiChannel write FiChannel;
    property sBankType: string read FsBankType write FsBankType;
    property iJYLX: Integer read FiJYLX write FiJYLX;
  end;


调用方法:
procedure TForm1.btn1Click(Sender: TObject);
var
  doc: TNativeXml;
  anode: TXmlNode;
  Resp: TRespparms;
  Writer: TsdXmlObjectWriter;
begin
  Resp := TRespparms.Create();
  Resp.bNeedQuery := False;
  Resp.sMsg := 'smge';
  Resp.sOrderNO := 'S1234';
  Resp.iTotal_fee := 23466;
  Resp.sTransaction_id := 'A9876ed2';
  Resp.sBankName := 'CCB';
  Resp.Fjlbh := 99;
  mmXml.Lines.Text := ObjectSaveToXmlString(Resp);

 坑:

要序列化的类最好是继承TPersistent

字段属性 一定要写成 property XX: string read FXX write FXX;  // 划重点

开始字段 直接写在Public  jlbh: Integer; 始终反序列化不成功,改成上面的写法正常

 

posted on 2021-03-15 16:57  EEEEEEEEEEEEEEEEEEE  阅读(93)  评论(0编辑  收藏  举报