Delphi 将对象转换为JSON字符串或TJSONObject


本文整理自网络,侵删。

 
type
  TPerson = record
  private
    FAge: Integer;
    FName: string;
  public
    property Name: string read FName write FName;
    property Age: Integer read FAge write FAge;
  end;

uses
  System.Generics.Collections,
  REST.Json;

procedure TForm1.Button1Click(Sender: TObject);
var
  Alice, Bob: TPerson;
  People: TList<TPerson>;
  S: string;
begin
  People := TList<TPerson>.Create;

  Alice.Name := 'Alice';
  Alice.Age := 20;
  People.Add(Alice);
  Bob.Name := 'Bob';
  Bob.Age := 30;
  People.Add(Bob);

  S := TJson.ObjectToJsonString(People);
  Memo1.Text := S;
end;


相关阅读 >>

Delphi mscomm 发送接收

Delphi通过idhttp和php交互

Delphi 校验手机号及身份证号

Delphi 压缩与修复access数据库

Delphi 通过进程id获取进程名

Delphi xe6调用android手机标准功能

Delphi 通过u盘方式加密

Delphi 如何将颜色值转换为html格式?

Delphi firedac 如何按整型(byte)读取 mysql tinyint(1) 类型字段?

Delphi文件管理类函数

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...