unit Unit1;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs,System.Generics.Defaults,System.Generics.Collections,
  Vcl.StdCtrls,REST.Json,DBXJSON, DBXJSONReflect,system.JSON;

type
  TForm1 = class(TForm)
    Button1: TButton;
    memLog: TMemo;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TPerson=class(TObject)
    name:String;
    age:Integer;
  end;

var
  Form1: TForm1;

implementation


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  aPerson:TPerson;
  dataList:TList<TPerson>;
  json:String;
  jo:TJSONObject;
begin
  try
    dataList:=TList<TPerson>.Create;
    aPerson:=TPerson.Create;
    aPerson.name:='中文';
    aPerson.age:=10;

    dataList.Add(aPerson);

    aPerson:=TPerson.Create;
    aPerson.name:='Tom';
    aPerson.age:=20;
    dataList.Add(aPerson);

    jo:=TJson.ObjectToJsonObject(dataList);
    memLog.Text:=jo.GetValue('items').ToString;
  finally
    dataList.Free;
  end;
end;

end.

 

posted on 2022-04-15 11:03  garfieldtom  阅读(197)  评论(0编辑  收藏  举报