lbidi,
Cita:
Empezado por lbidi
...Tengo el siguiente array en formato json y necesito parsearlo...
|
Revisa este código:
Código Delphi
[-]
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, uLkJSON;
type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
SL, FieldList : TStringList;
JS : TlkJSONobject;
i : Integer;
begin
SL := TStringList.Create;
SL.LoadFromFile(ExtractFilePath(Application.ExeName) + 'FileTest.json');
FieldList := TStringList.Create;
JS := TlkJSONobject.Create;
JS := TlkJSON.ParseText(SL.Text) as TlkJSONobject;
for i := 0 to JS.Count - 1 do
begin
if JS.FieldByIndex[i].SelfType <> jsNull then
FieldList.Add(JS.FieldByIndex[i].Value)
else
FieldList.Add(' ');
end;
ListBox1.Clear;
for i := 0 to FieldList.Count - 1 do
ListBox1.Items.Add(FieldList.Strings[i]);
SL.Free;
FieldList.Free;
JS.Free;
end;
end.
El código anterior en Delphi 7 sobre Windows 7 Professional x32,
Lee y analiza la estructura de un archivo .json (Msg #1) por medio de la librería lkJSON-1.07, como se muestra en la siguiente imagen:
Nota: La librería
lkJSON-1.07,
no necesita ser instalada,
solo se debe copiar la unidad uLkJSON.pas al directorio del proyecto o agregar la ruta de la misma en el Library Path de Delphi.
Espero sea útil
Nelson.