Ver Mensaje Individual
  #2  
Antiguo 02-08-2020
tiqui_loquito tiqui_loquito is offline
Miembro
 
Registrado: oct 2013
Posts: 56
Reputación: 11
tiqui_loquito Va por buen camino
Doy respuesta a lo que necesitaba

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
    { Private declarations }
  public
    { Public declarations }
    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.
Responder Con Cita