fpc序列objectlist为json
fpc序列objectlist为json
unit Unit1; {$mode delphi} interface uses fpjson, fpjsonrtti, Contnrs, //Generics.Collections, Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls; type { Ttest } Ttest = class private fid: string; published property id: string read fid write fid; end; { TForm1 } TForm1 = class(TForm) Button1: TButton; Memo1: TMemo; procedure Button1Click(Sender: TObject); private public end; var Form1: TForm1; implementation {$R *.lfm} { TForm1 } procedure TForm1.Button1Click(Sender: TObject); var s: TJSONStreamer; items: tobjectlist; item: Ttest; begin s := TJSONStreamer.Create(nil); items := tobjectlist.Create; item := ttest.Create; item.id:='中'; items.Add(item); item := ttest.Create; item.id:='国'; items.Add(item); memo1.Text:=s.ObjectToJSONString(items); //{ "Objects" : [{ "id" : "中" }, { "id" : "国" }] } s.Free; items.Free; end; end.
本文来自博客园,作者:{咏南中间件},转载请注明原文链接:https://www.cnblogs.com/hnxxcxg/p/17685443.html