Advertisement
danieleteti

DelphiMVCFramework Render(TTextWriter)

Apr 22nd, 2016
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.78 KB | None | 0 0
  1. procedure TMyController.Index;
  2. var
  3.   StringWriter: TStringWriter;
  4.   Writer: TJSONTextWriter;
  5.   oUser: String;
  6.   Arr: TArray<String>;
  7. begin
  8.   StringWriter := TStringWriter.Create();
  9.   Writer := TJsonTextWriter.Create(StringWriter);
  10.   try
  11.     Writer.Formatting := TJsonFormatting.Indented;
  12.     Writer.WriteStartObject;
  13.     Writer.WritePropertyName('Users');
  14.     Writer.WriteStartArray;
  15.     Arr := ['Daniele','Peter','Scott'];
  16.     for oUser in Arr do
  17.     begin
  18.       Writer.WriteStartObject;
  19.       Writer.WritePropertyName('UserName');
  20.       Writer.WriteValue(oUser);
  21.       Writer.WriteEndObject;
  22.     end;
  23.     Writer.WriteEndArray;
  24.     Writer.WriteEndObject;
  25.     Render(StringWriter, False);
  26.   finally
  27.     Writer.Free;
  28.     StringWriter.Free;
  29.   end;
  30. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement