본문 바로가기
Delphi/프로시저-함수

델파이 JSON to Object 한줄

by MonoSoft 2021. 7. 20.
728x90
반응형

델파이 JSON to Object 한줄

 

 

uses REST.JSON; 

// Also new System.JSON

 

TFoo = class

private

FFee : Integer;

FFoo : string;

published

property Foo : String read FFoo write FFoo;

property Fee : integer read FFee write FFee;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  Foo: TFoo;

begin

  Foo := TFoo.Create;

  try

    Foo.Foo := 'Hello World';

    Foo.Fee := 42;

    Memo1.Lines.Text := TJson.ObjectToJsonString(Foo);

  finally

    Foo.Free;

  end;

 

Foo := TJson.JsonToObject<tfoo>(Memo1.Lines.Text);

  try

    Foo.Fee := 100;

    Memo1.Lines.Add(TJson.ObjectToJsonString(Foo));

  finally

    Foo.Free;

  end;

end;

 

 

 

 

 

 

https://youtu.be/TSqWoFvjj5g

 

728x90
반응형

댓글