mein Tipp mach ne Klasse und nutzt ihn aus der Klasse raus.
das hier Hilft dir:
https://jsontodelphi.com/
der Aufruf ist dann ist dann nur
Delphi-Quellcode:
uses RootUnit;
function GetText(pJson:string):string;
var
Root: TRoot;
begin
Root := TRoot.Create;
try
Root.AsJson := pJson;
Result:= Root.Data.Translations.First.TranslatedText;
//oder per Index
//Result:= Root.Data.Translations.Items[0].TranslatedText;
finally
Root.Free;
end;
end;
Hier die Klasse
Delphi-Quellcode:
unit RootUnit;
interface
uses
Pkg.Json.DTO, System.Generics.Collections, REST.Json.Types;
{$M+}
type
TTranslations =
class;
TTranslations =
class
private
FTranslatedText:
string;
published
property TranslatedText:
string read FTranslatedText
write FTranslatedText;
end;
TData =
class(TJsonDTO)
private
[JSONName('
translations'), JSONMarshalled(False)]
FTranslationsArray: TArray<TTranslations>;
[GenericListReflect]
FTranslations: TObjectList<TTranslations>;
function GetTranslations: TObjectList<TTranslations>;
protected
function GetAsJson:
string;
override;
published
property Translations: TObjectList<TTranslations>
read GetTranslations;
public
destructor Destroy;
override;
end;
TRoot =
class(TJsonDTO)
private
FData: TData;
published
property Data: TData
read FData;
public
constructor Create;
override;
destructor Destroy;
override;
end;
implementation
{ TData }
destructor TData.Destroy;
begin
GetTranslations.Free;
inherited;
end;
function TData.GetTranslations: TObjectList<TTranslations>;
begin
Result := ObjectList<TTranslations>(FTranslations, FTranslationsArray);
end;
function TData.GetAsJson:
string;
begin
RefreshArray<TTranslations>(FTranslations, FTranslationsArray);
Result :=
inherited;
end;
{ TRoot }
constructor TRoot.Create;
begin
inherited;
FData := TData.Create;
end;
destructor TRoot.Destroy;
begin
FData.Free;
inherited;
end;
end.