Bueno, me puse a cacharrear un rato y aquí lo hice
Si hay una manera más optima de hacerlo, se los agradecería.
Por si a alguien le sirve.
Delphi 10.3 community edition
Dos memos y dos botones en el formulario
Código Delphi
[-]
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,System.JSON, sYSTEM.JSON.Types,
System.JSON.Writers,System.JSON.Builders;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
Memo1: TMemo;
Memo2: TMemo;
procedure Button2Click(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
public
procedure ParseJSonValue;
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
StringWriter:TStringWriter;
Writer:TJsonTextWriter;
Builder : TJSONObjectBuilder;
LJsonResponse: TJSONObject;
begin
Memo1.Lines.Clear;
StringWriter := TStringWriter.Create();
writer := TJsonTextWriter.Create(StringWriter);
Builder := TJSONObjectBuilder.Create(Writer);
try
Writer.Formatting := TJsonFormatting.Indented;
Builder
.BeginObject
.Add('Estado','Error')
.Add('Mensaje','La información del token no fue enviada correctamente.')
.Add('Entorno','3')
.Add('Errores','4')
.Add('XmlBase64','5')
.Add('message','6')
.EndObject;
Memo1.Lines.Add(StringWriter.ToString);
finally
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
ParseJSonValue
end;
procedure TForm1.ParseJSonValue;
procedure ParseJson;
var
LJsonObj : TJSONObject;
LJPair : TJSONPair;
LProducts : TJSONValue;
LProduct : TJSONValue;
LProduct1 : TJSONValue;
LItem : TJSONValue;
LIndex : Integer;
LSize : Integer;
begin
LJsonObj := TJSONObject.ParseJSONValue(Memo1.Text) as TJSONObject;
try
LSize:= TJSONArray(LJsonObj).Size;
for LIndex:=0 to LSize-1 do
begin
LProduct := TJSONArray(LJsonObj.Get(LIndex).JsonValue);
LProduct1 := TJSONArray(LJsonObj.Get(LIndex).JsonString);
LJPair := TJSONPair(LProduct);
Memo2.Lines.Add(StringReplace(LProduct1.ToString,'"','',[rfReplaceAll]));
Memo2.Lines.Add(StringReplace(LJPair.ToString,'"','',[rfReplaceAll]));
end;
finally
LJsonObj.Free;
end;
end;
begin
ParseJson;
end;
end.