I’m creating a nested JSON object in Delphi using this code:
var jo:TJsonObject;
try
jo := TJsonObject.Create;
jo.AddPair('data', TJsonObject.Create);
with jo.GetValue<TJsonObject>('data') do begin
jo.AddPair('details', TJSONObject.Create);
with jo.GetValue<TJsonObject>('details') do begin
jo.AddPair('foo', 'bar');
end;
end;
finally
FreeAndNil(jo);
end;
It works and is not too ugly, but I’m wondering if there is a nicer way to structure the code so I don’t have to first add each child object and then look it up on the next line using GetValue
?
1