JSON serialized Object

Source: Internet
Author: User

The new Datasnap already supports tparams as a parameter inside the remote method, automatically sequences the tparams without having to manually sequence it.

This is just a way to record some JSON sequence usage, no practical meaning

Unit userialize;
Interface
Uses
System.sysutils, Data.Win.ADODB, Data.dbxjson, Data.dbxjsonreflect,
System.variants, data.db;
Type
Tserialize = Class
Public
function Serialize (const moduleid:string; Sqlid:integer; p:tparameters): Tjsonvalue; overload;
function Serialize (const moduleid:string; Sqlid:integer; P:tparams): Tjsonvalue; overload;
End
Tdeserialize = Class
Private
fmoduleid:string;
Fsqlid:integer;
Public
Property moduleid:string read Fmoduleid;
Property Sqlid:integer read Fsqlid;
function Deserialize (v:tjsonvalue; p:tparameters): tdeserialize; overload;
function Deserialize (v:tjsonvalue; P:tparams): tdeserialize; overload;
End
Implementation
function tserialize.serialize (const moduleid:string; Sqlid:integer; p:tparameters): Tjsonvalue;
Var
Jo:tjsonobject;
Ja:tjsonarray;
I:integer;
Begin
Result: = nil;
If ModuleID = "then Exit;
If Sqlid = 0 then Exit;
If not Assigned (P) then Exit;
JA: = tjsonarray.create;
Ja. AddElement (Tjsonstring.create (ModuleID));
Ja. AddElement (Tjsonnumber.create (sqlid));
I: = 0;
While I < P.count do
Begin
JO: = tjsonobject.create;
Jo. Addpair (' Name ', p.items[i]. Name);
Jo. Addpair (' DataType ', tjsonnumber.create (Ord p.items[i). (DataType)));
Jo. Addpair (' Value ', Vartostr (p.items[i). Value));
Ja. AddElement (Jo);
INC (i);
End
Result: = ja;
End
function tserialize.serialize (const moduleid:string; Sqlid:integer; P:tparams): Tjsonvalue;
Var
Jo:tjsonobject;
Ja:tjsonarray;
I:integer;
Begin
Result: = nil;
If ModuleID = "then exit;
If Sqlid = 0 Then exit;
If not Assigned (p) then exit;
JA: = tjsonarray.create;
Ja. AddElement (Tjsonstring.create (ModuleID));
Ja. AddElement (Tjsonnumber.create (sqlid));
I: = 0;
While I < P.count do
Begin
JO: = tjsonobject.create;
Jo. Addpair (' Name ', p.items[i]. Name);
Jo. Addpair (' DataType ', tjsonnumber.create (Ord p.items[i). (DataType)));
Jo. Addpair (' Value ', Vartostr (p.items[i). Value));
Ja. AddElement (Jo);
INC (i);
End
Result: = ja;
End
function Tdeserialize.deserialize (v:tjsonvalue; p:tparameters): tdeserialize;
Var
I:integer;
Ja:tjsonarray;
Jo:tjsonobject;
Begin
Result: = nil;
If not Assigned (P) then exit;
If V.null then exit;
P.clear;
JA: = v as Tjsonarray;
Fmoduleid: = tjsonstring (ja. Get (0)). Value;
Fsqlid: = Tjsonnumber (ja. Get (1)). Asint;
For I: = 2 to Ja. Size-1 do
Begin
JO: = Tjsonobject (ja. Get (i));
P.createparameter (Jo. Get (' Name '). Jsonvalue.value,
Tfieldtype, Tjsonnumber (Jo. Get (' DataType '). Jsonvalue). Asint),
Pdinput,
SizeOf (Jo. Get (' Value '). Jsonvalue.value),
Jo. Get (' Value '). Jsonvalue.value);
End
Result: = self;
End
function Tdeserialize.deserialize (v:tjsonvalue; P:tparams): tdeserialize;
Var
I:integer;
Ja:tjsonarray;
Jo:tjsonobject;
Begin
Result: = nil;
If not Assigned (p) then exit;
If V.null then exit;
P.clear;
JA: = v as Tjsonarray;
Fmoduleid: = tjsonstring (ja. Get (0)). Value;
Fsqlid: = Tjsonnumber (ja. Get (1)). Asint;
For I: = 2 to Ja. Size-1 do
Begin
JO: = Tjsonobject (ja. Get (i));
P.createparam (Tfieldtype (Tjsonnumber) (Jo. Get (' DataType '). Jsonvalue). Asint),
Jo. Get (' Name '). Jsonvalue.value,
Ptinput);
P.items[i]. Value: = Jo. Get (' Value '). Jsonvalue.value;
P.items[i]. Size: = SizeOf (jo. Get (' Value '). Jsonvalue.value);
End
End
End.

JSON serialized Object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.