Delphi 11 Converting a record to a Json string (Serialization) - Quick Clip
Описание
In this video we will show very quickly how to use the System.Json.Serializer to convert a record to a Json String.
Chapters:
00:00 Intro
00:08 New Delphi Console Project
00:10 "Use" Unit System.JSON.Serializers
00:17 Make TMyRecord record
00:28 Setup JSON console output
00:40 Create TJsonSerializer
00:51 Declare TMyRecord Instance
01:08 readln to pause output
01:14 run program (Console output)
Software Used:
Delphi Enterprise 11:
https://www.embarcadero.com/products/delphi/starter/free-download
MMX – speed up your Delphi development:
https://www.mmx-delphi.de/
Program Source:
program Project8;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
System.JSON.Serializers;
type
TMyRecord = record
Name: String;
Date: TDateTime;
Money: Double;
Years: Integer;
end;
begin
try
var lSerializer := TJsonSerializer.Create;
try
var lMyRecord: TMyRecord;
lMyRecord.Name := 'Jim';
lMyRecord.Date := EncodeDate(2022,5,16);
lMyRecord.Money := 3412;
lMyRecord.Years := 12;
Writeln(lSerializer.Serialize(lMyRecord));
Readln;
finally
FreeAndNil(lSerializer);
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end.
#delphi #json #export #serialization #TJsonSerializer #serializer #embarcadero
Рекомендуемые видео



















