unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type 
  TForm1 =class (TForm)
    Button1: TButton;
    Button2: TButton;
    Button3: TButton;
    procedure Button1Click (Sender: TObject);
    procedure Button2Click (Sender: TObject);
    procedure Button3Click (Sender: TObject);
  end ;

var
  Form1: TForm1;

implementation

{$ R * .dfm}

uses SuperObject;

//Add to
procedure TForm1.Button1Click (Sender: TObject);
var
  jo: ISuperObject;
  i: Integer;
begin
  jo: = TSuperObject.Create;

  for i: =0 to 9 do jo.I ['N' + IntToStr (i)]: = i;
  ShowMessage (jo.AsJSon (True));

  for i: =0 to 9 do jo.S ['N' + IntToStr (i)]: = IntToStr (i);
  ShowMessage (jo.AsJSon (True));

  for i: =0 to 9 do jo.B ['N' + IntToStr (i)]: = Odd (i);
  ShowMessage (jo.AsJSon (True));

  for i: =0 to 9 do jo.D ['N' + IntToStr (i)]: = i / 2;
  ShowMessage (jo.AsJSon (True));

  for i: =0 to 9 do jo.O ['N' + IntToStr (i)]: = SO ('{"A": "B"}');
  ShowMessage (jo.AsJSon (True));

  jo.Clear;
  ShowMessage (jo.AsJSon (True));
end ;

// Modify and delete
procedure TForm1.Button2Click (Sender: TObject);
var
  jo: ISuperObject;
  str: string ;
begin 
  jo: = SO ('{"Name": "张三", "Age": 88}');
  ShowMessage (jo.AsJSon (False, False));

  jo.S ['Name']: = 'Li Si';
  jo.I ['Age']: = 18;
  ShowMessage (jo.AsJSon (False, False));

  jo.Delete ('Age');
  ShowMessage (jo.AsJSon (False, False));

  jo.D ['Size']: = 1.83;
  ShowMessage (jo.AsJSon (False, False));
end ;

// TSuperArray add, delete, change and view
procedure TForm1.Button3Click (Sender: TObject);
var
  jo, item: ISuperObject;
  ja: TSuperArray;
  i: Integer;
  str: string ;
begin 
  jo: = SO ('{"Hobby": ["Programming", "Playing"]}');
  ShowMessage (jo.AsJSon (False, False));

  jo.A ['Hobby'] .Add (SO ('watch TV'));
  ShowMessage (jo.AsJSon (False, False));

  ja: = jo.A ['Hobby'];
  ja.Add (SO ('Swim'));
  ShowMessage (jo.AsJSon (False, False));

  ja.Insert (0, SO ('go to bed'));
  ShowMessage (jo.AsJSon (False, False));

  ja.Delete (0);
  ShowMessage (jo.AsJSon (False, False));

  ja.D [0]: = 3.14;
  ShowMessage (jo.AsJSon (False, False));

  ja.O [0]: = SO ('()');
  ShowMessage (jo.AsJSon (False, False));

  str: = '';
  for i: =0 to ja.Length-1 do str: = Format ('% s% s', [str, ja.S [i]]);
  ShowMessage (Trim (str));

  str: = '';
  for itemin jo ['Hobby'] do str: = Format ('% s% s', [str, item.AsString]);
  ShowMessage (Trim (str));

  ja.Clear;
  ShowMessage (jo.AsJSon (False, False));
end ;

end .