RTC is the most professional Web application server of Delphi, and if the client wants to use JSON, then using RTC should also be a
Very good choice. Let's take an example of using the RTC Web server to return the database JSON.
Create a new program form, place the controls:
Where the properties of the server are
Note that this piece does not select multi-threading, because in this simple example, the database pool is not involved for the time being,
I'll do the database pool example later.
Properties of the RtcDataProvider1
Then set the UNIDAC database connection properties, I use Firebird as the database here.
and set the event to the following code:
Procedure Tform2.button1click (sender:tobject); Begin Server. Listen (); Button1.caption:= ' started '; Button1.enabled:=false;end;
Procedure Tform2.rtcdataprovider1checkrequest (sender:trtcconnection); begin with Trtcdataserver (Sender) do if uppercase (request.filename) = '/getdata ' Then Accept;end;
Procedure tform2.rtcdataprovider1datareceived (sender:trtcconnection); var ds:trtcdataset; R:trtcvalue; ss:string; S:trtchugestring;begin with trtcdataserver (Sender) does if Request.complete then begin Ds:= Trtcdataset.create; R:=trtcvalue.create; S:=trtchugestring.create; Try CX. Sql. Clear; CX.SQL.ADD (' select * from BMB '); Cx. Open; DELPHIDATASETTORTC (cx,r.newdataset); R.to_json (s); Ss:=s.get; Write (ss); Cx. Close; Finally DS. Free; R.free; S.free; End; End;end;
Then compile and run, note to manually add the RTCDB and rtcfaststrings two unit references.
Now we enter Http://127.0.0.1/getdata in the browser
The JSON string for the database output will be displayed
Oh, you can find that the RTC JSON pass inside the Chinese character directly into the Unicode code.
Now, you can interpret the resulting data at the client's discretion.
Turn (Delphi new Cave): Use Delphi to develop multi-tier applications (17) return JSON using the RTC Web server