have been looking forward to Delphi can directly support the "regular expression" and "JSON";
When Delphi 2009 came in, there was JSON, but it was not good, so I tried a little bit. This is the previous link: what is JSON?
Delphi 2010 with two related units: Dbxjson, Dbxjsonreflect seems very powerful, but mainly to datasnap preparation; Try a half-day, also very disappointed: may give Datasnap network data pass enough, but too shabby, seems to have not finished, to Chinese support also have problems.
I want to wait, find a third party, really found a surprise: Json–superobject v1.1 (Introduction, download), Henri gourvest masterpiece!
There is also an XML-related unit, take a slow look.
Let's start with a simple test:
UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, Stdctrls;typeTForm1 =class(Tform) Button1:tbutton; Button2:tbutton;procedureButton1Click (Sender:tobject);procedureButton2click (Sender:tobject);End;varForm1:tform1;Implementation{$R *.DFM}usesSuperobject;//superobject advocates the use of interfaces; ParseString is the class method for Tsuperobject classesprocedureTform1.button1click (Sender:tobject);varJo:isuperobject;beginJO: = tsuperobject.parsestring (' {' No1 ': ' Zhang San ', ' No2 ': ' John Doe '} '); ShowMessage (jo[' No1 ']. asstring);{Zhang San}End;//have a common function so, can be easily implemented interfaceprocedureTform1.button2click (Sender:tobject);varJo:isuperobject;beginJO: = SO (' {' No1 ': ' Zhang San ', ' No2 ': ' John Doe '} '); ShowMessage (jo[' No2 ']. asstring);//John DoeEnd;End.
Why use interface-based?
I guess: A JSON object may contain too many sub-objects, it is easier to release the interface, because it is automatically released;
In addition, the function of the new iountils unit of Delphi 2010 is given by means of structure, and the structure is self-releasing;
Automatic release! Is this going to be a direction? But it does write a lot less code.
JSON Superobject (1)