JSON SuperObject (13) SO and SA Functions in Delphi
unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 =class (TForm) Button1: TButton; Button2: TButton; procedure Button1Click (Sender: TObject); procedure Button2Click (Sender: TObject); end ; var Form1: TForm1; implementation {$ R * .dfm} uses SuperObject, TypInfo; procedure TForm1.Button1Click (Sender: TObject); var jo: ISuperObject; begin jo: = SO (['A',1, 'B',2.5, 'C','xyz', 'D', True]); ShowMessage (jo.AsJSon); // {"D": true, "C": "xyz", "B": 2.5, "A": 1} {Display type name} ShowMessage (GetEnumName (TypeInfo (TSuperType), Ord (jo.DataType))); // stObject jo: = SO (3.14); ShowMessage (jo.AsJSon); // 3.14 {Display type name} ShowMessage (GetEnumName (TypeInfo (TSuperType), Ord (jo.DataType))); // stDouble jo: = SA (['A',1, 'B',2.5, 'C','xyz', 'D', True]); ShowMessage (jo.AsJSon); {Display type name} ShowMessage (GetEnumName (TypeInfo (TSuperType), Ord (jo.DataType))); // stArray end ; // SA another example procedure TForm1.Button2Click (Sender: TObject); var jo, ja: ISuperObject; begin ja: = SA (['x','y','z']); jo: = SO ('{A: 1, B: 2}'); jo ['B']: = ja; ShowMessage (jo.AsJSon); // {"B": ["x", "y", "z"], "A": 1} end ; end .