zoukankan      html  css  js  c++  java
  • 泛型数组 + 记录类型 + Json 之间的转换

    unit Unit3;
    
    interface
    
    uses
      Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
      Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, System.Generics.Collections;
    
    type
      TForm3 = class(TForm)
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;
    
    var
      Form3: TForm3;
    
    /// <summary>
    /// 这里注意必须在interface部分声明.
    /// </summary>
    type TRen = record
      name: string;
      age: Integer;
    end;
    
    implementation
    
    {$R *.dfm}
    
    uses qjson;
    
    procedure TForm3.Button1Click(Sender: TObject);
    const
      MyJson: string = '[{"name":"群主","age":100},{"name":"老衲","age":100}]';
    var
      MyRenAry: TArray<TRen>;
      MyQj: TQJson;
    begin
      MyQj := TQJson.Create;
      try
        //---------------------------------------
        MyQj.Parse(MyJson);
        MyQj.ToRtti(@MyRenAry,TypeInfo(TArray<TRen>));
    
        ShowMessage(MyRenAry[0].name);
    
        //---------------------------------------
        MyQj.FromRtti(@MyRenAry,TypeInfo(TArray<TRen>));
        ShowMessage(MyQj.AsJson);
      finally
        MyQj.Free;
      end;
    end;
    
    end.
  • 相关阅读:
    hdu-1114
    hdu2546
    POJ-3126
    POJ-1915
    ZOJ-1709
    Codeforces 847H
    Codeforces 847C
    Codeforces 847I
    Codeforces 847E
    算法笔记--矩阵及矩阵快速幂
  • 原文地址:https://www.cnblogs.com/del88/p/4387320.html
Copyright © 2011-2022 走看看