unit Unit1;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, fphttpclient, opensslsockets, fpjson, StrUtils;
type
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
private
public
procedure GetJsonInfo(jd: TJSONData; level: Integer);
end;
var
Form1: TForm1;
implementation
{$R *.lfm}
{ TForm1 }
var
a_count, o_count, s_count, n_count, b_count, e_count, u_count: Integer;
procedure TForm1.Button1Click(Sender: TObject);
var
hc: TFPHttpClient;
jd: TJSONData;
begin
a_count := 0;
o_count := 0;
s_count := 0;
n_count := 0;
b_count := 0;
e_count := 0;
u_count := 0;
hc := TFPHttpClient.Create(nil);
hc.AllowRedirect := True;
Memo1.Lines.Text := hc.Get('https://docs.google.com/uc?export=download&id=1G_9faCq0UbTjFVB6UpMASq5rQrzrN9OU');
hc.Free;
jd := GetJSON(Memo1.Lines.Text);
Memo2.Lines.Clear;
Memo2.Lines.BeginUpdate;
GetJsonInfo(jd, 0);
Memo2.Lines.EndUpdate;
Memo2.Lines.Add(Format('Count: array - %d, object - %d, string - %d, number - %d, boolean - %d, null - %d, unknown - %d',
[a_count, o_count, s_count, n_count, b_count, e_count, u_count]));
jd.Free;
end;
procedure TForm1.GetJsonInfo(jd: TJSONData; level: Integer);
var
i: Integer;
s: String;
jo: TJSONObject;
begin
jo := TJSONObject(jd);
for i := 0 to jo.Count - 1 do
begin
s := IntToStr(level) + ': ';
if level > 0 then
s := s + DupeString(' ', level);
case jo.Items[i].JSONType of
jtUnknown:
begin
Inc(u_count);
s := s + jo.Names[i] + ' > ' + 'UNKNOWN';
end;
jtNumber:
begin
Inc(n_count);
s := s + jo.Names[i] + ' > ' + 'NUMBER';
end;
jtString:
begin
Inc(s_count);
s := s + jo.Names[i] + ' > ' + 'STRING';
end;
jtBoolean:
begin
Inc(b_count);
s := s + jo.Names[i] + ' > ' + 'BOOLEAN';
end;
jtNull:
begin
Inc(e_count);
s := s + jo.Names[i] + ' > ' + 'NULL';
end;
jtArray:
begin
Inc(a_count);
s := s + jo.Names[i] + ' > ' + 'ARRAY count ' + IntToStr(jo.Items[i].Count);
GetJsonInfo(jo.Items[i], level + 1);
end;
jtObject:
begin
Inc(o_count);
s := s + ' > ' + 'OBJECT';
GetJsonInfo(jo.Items[i], level + 1);
end;
else
begin
Inc(u_count);
s := s + jo.Names[i] + ' > ' + 'UNKNOWN';
end;
end;
Memo2.Lines.Add(s);
end;
end;
end.