{
全能中间件 —— 简单、高效、稳定、安全的三层中间件 1.支持 多账套多数据库,包括SQLite, MySQL, SQL Server, Oracle, PostgreSQL, DB2, SQL Anywhere,Firebird等多种数据库。
2.支持 快速开发,封装了 TRFConnection 和 TRFDataSet 控件供客户端使用,传统两层应用轻松升级为三层应用。
3.支持 数据压缩、加密传输,效率和安全有保障。
4.支持 数据连接池,提高并发响应速度。
5.支持 客户端执行SQL语句,存储过程,亦可以把逻辑SQL放在中间层,控制权由您一手掌握。
6.支持 Delta更新,比传统的拼接SQL更新方式效率高,兼容性更好。
7.支持 SQL 参数化查询、 分页查询。
8.支持 多表事务更新,会保证数据的一致性。
9.支持 多表联合查询更新其中一个表。
10.支持 多平台开发(Windows/Android/iOS/OS X),各平台使用方法一致。
11.支持 7x24小时长时间稳定运行,已经过多个正式项目长时间考验。 Copyright @2014-2017 by QQ:64445322
All rights reserved. QQ群:339616649
}
unit Unit1; interface uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, System.JSON.Writers, System.JSON.Types, System.JSON.Builders,
System.JSON.Readers, Vcl.StdCtrls; type
TForm1 = class(TForm)
btnBuilder: TButton;
Memo1: TMemo;
btnReader: TButton;
Memo2: TMemo;
procedure FormCreate(Sender: TObject);
procedure btnBuilderClick(Sender: TObject);
procedure btnReaderClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
//http://docwiki.embarcadero.com/RADStudio/Tokyo/en/JSON#JSON_Frameworks
TJSONBuilder = class(TJSONObjectBuilder)
private
FJsonWriter: TJsonTextWriter;
FStringWriter: TStringWriter;
FStringBuilder: TStringBuilder;
strict private
class var
FJsonBuilder: TJSONBuilder; class destructor Destroy;
public
constructor Create(const AFormatting: TJsonFormatting = TJsonFormatting.None);
destructor Destroy; override; function ToJSON: string; class function NewBuilder(const AFormatting: TJsonFormatting = TJsonFormatting.None): TJSONBuilder; static;
end; TJsonObjectReader = class (TJsonTextReader)
private
FStringReader : TStringReader;
strict private
class var
FJsonObjectReader: TJsonObjectReader;
class destructor Destroy;
public
constructor Create(const AJson: string);
destructor Destroy; override; class function NewReader(const AJson:string): TJsonObjectReader; static;
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.btnBuilderClick(Sender: TObject);
var
Builder: TJSONBuilder;
begin
Builder := TJSONBuilder.NewBuilder(TJsonFormatting.Indented);
Builder
.BeginObject
.BeginArray('Transaction')
.BeginObject.Add('id', )
.Add('firstName', 'John')
.Add('lastName', 'Doe')
.Add('price', 2.1)
.AddNull('parent_id')
.Add('validated', True)
.EndObject
.BeginObject
.Add('id', )
.Add('firstName', 'Anna')
.Add('lastName', 'Smith')
.Add('price', 4.5)
.AddNull('parent_id')
.Add('validated', False)
.EndObject
.BeginObject
.Add('id', )
.Add('firstName', 'Peter')
.Add('lastName', 'Jones')
.Add('price', 3.6)
.AddNull('parent_id')
.Add('validated', True)
.EndObject
.EndArray
.EndObject; Memo1.Text := Builder.ToJSON; end; procedure TForm1.btnReaderClick(Sender: TObject);
var
Reader:TJsonObjectReader;
begin
Memo2.Clear;
Reader:=TJsonObjectReader.NewReader(Memo1.Text); while Reader.Read do
case Reader.TokenType of
TJsonToken.PropertyName:
Memo2.Lines.Add(Reader.Value.AsString);
TJsonToken.String:
Memo2.Lines[Memo2.Lines.Count-] := Memo2.Lines[Memo2.Lines.Count-] + ': ' +Reader.Value.AsString;
end;
end; procedure TForm1.FormCreate(Sender: TObject);
begin
ReportMemoryLeaksOnShutdown := True;
end; { TJSONBuilder } constructor TJSONBuilder.Create(const AFormatting: TJsonFormatting);
begin
FJsonBuilder := nil;
FStringBuilder := TStringBuilder.Create;
FStringWriter := TStringWriter.Create(FStringBuilder);
FJsonWriter := TJsonTextWriter.Create(FStringWriter);
FJsonWriter.Formatting := AFormatting;
inherited Create(FJsonWriter);
end; destructor TJSONBuilder.Destroy;
begin
FreeAndNil(FJsonWriter);
FreeAndNil(FStringWriter);
FreeAndNil(FStringBuilder);
inherited;
end; class destructor TJSONBuilder.Destroy;
begin
FreeAndNil(FJsonBuilder);
end; class function TJSONBuilder.NewBuilder(const AFormatting: TJsonFormatting): TJSONBuilder;
begin
if FJsonBuilder <> nil then
FreeAndNil(FJsonBuilder); FJsonBuilder := TJSONBuilder.Create(AFormatting); Result := FJsonBuilder;
end; function TJSONBuilder.ToJSON: string;
begin
Result := FStringBuilder.ToString;
end; { TJsonObjectReader } constructor TJsonObjectReader.Create(const AJson: string);
begin
FStringReader:= TStringReader.Create(AJson);
inherited Create(FStringReader) ;
end; class destructor TJsonObjectReader.Destroy;
begin
FreeAndNil(FJsonObjectReader);
end; destructor TJsonObjectReader.Destroy;
begin
FreeAndNil(FStringReader);
inherited;
end; class function TJsonObjectReader.NewReader(const AJson:string): TJsonObjectReader;
begin
if FJsonObjectReader <> nil then
FreeAndNil(FJsonObjectReader); FJsonObjectReader := TJsonObjectReader.Create(AJson); Result := FJsonObjectReader;
end; end.
运行效果如图: