Einzelnen Beitrag anzeigen

Schokohase
(Gast)

n/a Beiträge
 
#2

AW: Erzeugen und Freigeben von TJSONTextWriter wirklich so umständlich?

  Alt 20. Feb 2019, 10:11
So würde man es ja normalerweise machen:
Delphi-Quellcode:
function TmyClass.GetInfoAsJSON: string;
var
  jWriter: TJsonTextWriter;
  textWriter: TTextWriter;
begin
  textWriter := TStringWriter.Create;
  try
    jWriter:=TJsonTextWriter.Create(textWriter);
    try
      jWriter.WriteStartObject;
      jWriter.WritePropertyName('values');
      jWriter.WriteValue('wuppdi');
      jWriter.WriteEndObject;
      Result:=jWriter.Writer.ToString;
    finally
      jWriter.Free;
    end;
  finally
    textWriter.Free;
  end;
end;
oder alternativ auch so
Delphi-Quellcode:
function TmyClass.GetInfoAsJSON: string;
var
  jWriter: TJsonTextWriter;
  textWriter: TTextWriter;
begin
  jWriter := nil;
  textWriter := TStringWriter.Create;
  try
    jWriter:=TJsonTextWriter.Create(textWriter);
    jWriter.WriteStartObject;
    jWriter.WritePropertyName('values');
    jWriter.WriteValue('wuppdi');
    jWriter.WriteEndObject;
    Result:=jWriter.Writer.ToString;
  finally
    jWriter.Free;
    textWriter.Free;
  end;
end;
  Mit Zitat antworten Zitat