procedure TForm2.Button1Click(Sender: TObject); var sb: TStringBuilder; sw: TStringWriter; jtw: TJsonTextWriter; job: TJSONObjectBuilder; begin sb := TStringBuilder.Create; sw := TStringWriter.Create(sb); jtw := TJsonTextWriter.Create(sw); jtw.Formatting := TJsonFormatting.Indented; job := TJSONObjectBuilder.Create(jtw); job .BeginObject .BeginArray(‘数组‘) .BeginObject.Add(‘id‘, 123) .Add(‘Name‘, ‘名称一‘) .AddNull(‘parent_id‘) .EndObject .EndArray .EndObject; Memo1.Text := sb.ToString; (*输出的json { "数组": [ { "id": 123, "Name": "名称一", "parent_id": null } ] } *) end;
System.JSON.Builders.pas
delphi10 berlin增加的新单元,都说用它构建json方便。
uses
System.JSON.Writers, System.JSON.Types, System.JSON.Builders;
原文地址:https://www.cnblogs.com/hnxxcxg/p/14708803.html
感谢咏南的分享!