Go: The best JSON code base for Delphi Language Mormot Learning Note 1

Source: Internet
Author: User
Tags sqlite database

Mormot No control installation, add directly to the Lib path,
Add syncommons,syndb directly to the project until uses.

---------------------------------------------------------

It is necessary to construct and parse the JSON object in the network programming.
This Delphi xe+ comes with:
{$IF compilerversion>22}, system.json{$ELSE}, dbxjson{$IFEND}
However, do not use, we prefer superobject. I've been using jsondataobjects for a long time.
Today to introduce to you this set of JSON code library is "The Outer man", the body with a peerless martial arts, and obscurity, this is the Mormot Series development Framework. This is an open source framework that features super-powerful, learning curve walls.

http://synopse.info/

Project name:synopse Mormot Framework
Document Name:software Architecture Design
Document revision:1.18
Date:may 27, 2016
Project Manager:arnaud Bouchez

This is a PDF document:
Http://synopse.info/files/pdf/Synopse%20mORMot%20Framework%20SAD%201.18.pdf
The amount of information reached an astonishing 2127 pages. Most people were frightened by the document, and missed the chance to cultivate this "peerless skill".
Today we're going to pick out the JSON programming list and see what's magical about Mormot.
Using Mormot is not as difficult as you might think, using JSON only requires referencing a file syncommons. Let's take a look at the code and compare Superobject with Mormot:

Const CSTMAXTEST = 100000;

Procedure Tform1.testso;
var jo:isuperobject; I:int64; Sw:tstopwatch;
Begin
SW: = Tstopwatch.create;
JO: = SO ();
I: = 0;
While I < cstmaxtest do begin
Jo. s[' Name ']: = ' This is a Str ' + inttostr (i);
Jo. I[' age ']: = i;
Jo. o[' List ': = SO (' [1, ' Hello ', 5,{' name ': ' C5soft ', ' Age ': 50}] ');
If i =
Log (' so: ' + Jo. Asjson ());
Inc (I);
End
Log (' superobject: ' + SW. Stop ());
Sw.free;
End

Procedure TFORM1.TESTMJ;
var jo:variant; I:int64; Sw:tstopwatch;
Begin
Tdocvariant.new (Jo);;
SW: = Tstopwatch.create;
I: = 0;
While I < cstmaxtest do begin
Jo. Name: = ' This is a Str ' + inttostr (i);
Jo. Age: = i;
Jo. List:=_json (' [1, ' Hello ', 5,{' name ': ' C5soft ', ' Age ': 50}] ');
If i =
Log (' MJ: ' + Variantsavejson (Jo));
Inc (I);
End
Log (' Mormot JS: ' + SW. Stop ());
Sw.free;
End

Do a 100,000-time test, which is the result of the output:
so:{"Age": +, "name": "Str100", "List": [1, "Hello", 5,{"age": "Name": "C5soft"}]}
superobject:00:01.561
mj:{"name": "This was a Str100", "age": +, "List": [1, "Hello", 5,{"name": "C5soft", "Age": 50}]}
Mormot js:00:00.326

found that, Mormot faster than superobject too much, do the same job, Superobject time is Mormot 5 times times.
There are two other benefits to using Mormot:
One, use Jo. name instead of jo.s[' name ') more intuitive
Second, set a breakpoint in the debug phase, observe the value of Jo, Delphi tells you: {"Name": "This is a Str100", "Age": "" List ": [1," Hello ", 5,{" Name ":" C5soft "," Age ": 50}
And you go after Superobject's jo,delphi can only tell you that is an object, the specific value is how much, she said "too complex, a word can do", the result of nothing to see.

Next trailer: Build HTTP service under Windows, Discard Indy (intraweb), use IOCP (DIOCP) instead? Wrong! With HTTP. Sys is the king, all this mormot has been quietly ready for us.

http://bbs.2ccc.com/topic.asp?topicid=511839

---------------------------------------------------------

I tested, I a table in a single fetch more than 120,000 data, the server-side generated JSON string time less than 3 seconds, the program and database are on my machine, do not know the accuracy of the test does not

---------------------------------------------------------

Mormot Internal integrated Database is Sqlite,mormot can connect any current popular database, Mormot also can not connect any database, use memory table to work.

When it comes to SQLite, it's also very X-ray, very unique. This is a database of dynamic data types, where you can create a table without specifying a field type, specifying a data type such as an integer, or you can save data of a string type. This is the current open source, cross-platform, the smallest amount of code database. If the amount of data is small and you want to integrate it into the executable (embbed), SQLite is a good choice.

If you want to output very large data to the terminal interface, be sure to use paging. Even if Delphi generates JSON data
Not slow, the network transmission speed is not fast, front-end (such as browser) assembly data is not fast. SQLite's Select supports paging:
SELECT ... From ... WHERE ... ORDER by: LIMIT ... OFFSET ...

No Mormot, can use Disqlite, only can do stand-alone version of the software, with Mormot, using SQLite database can do c/s architecture software, and very convenient to have 3Tier, 4Tier.

Go: The best JSON code base for Delphi Language Mormot Learning Note 1

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.