Delphi 2010 Bringing two related units: DBXJSON and DBXJSONReflect seem to be very powerful, but mainly for DataSnap; I tried for a long time, and I was disappointed: Maybe enough for DataSnap network data transmission, but too rude, it seems like not finished , There is also a problem with Chinese support.

I ca n’t wait, find a third party, I really found a surprise: JSON – SuperObject v1.1 ( introduction,download), Henri Gourvest’s masterpiece!

There is also a unit related to XML, Take your time.

Let’s start with a simple test:

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;

// SuperObject promotes the use of interfaces; ParseString is the Class method of the TSuperObject class
procedure TForm1.Button1Click (Sender: TObject);
var
  jo: ISuperObject;
begin 
  jo: = TSuperObject.ParseString ('{"No1": "XXX", "No2": "YYY"}');
  ShowMessage (jo ['No1'] .AsString); {XXX}
end ;

// There is a common function SO, which can easily implement the interface
procedure TForm1.Button2Click (Sender: TObject);
var
  jo: ISuperObject;
begin 
  jo: = SO ('{"No1": "XXX", "No2": "YYY"}');
  ShowMessage (jo ['No2'] .AsString); // Li Si
end ;

end .


Why use interfaces?

I guess: There may be too many sub-objects in a JSON object. It is more convenient to release with an interface, because it is automatically released.

In addition, the function of the IOUntils unit newly given in Delphi 2010 is structured. Given, the structure is also self-releasing;

auto-releasing! Is this a direction? But it does write a lot less code