DelphiFan Magazine

Top Menu

Main Menu

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS

logo

DelphiFan Magazine

  • DELPHI
  • CODE SAMPLES
  • FIREMONKEY
  • DATABASE
  • RELEASES
  • VIDEOS
  • REVIEW
  • TECH NEWS
  • How to add a server application written in UNIGUI to startup?

  • UniGUI Expiry Link Anonymizer

  • UniGUI Add CAPTCHA to the WEB project

  • UniGui. Unique hybrid of Delphi and JS

  • How to transform a blob field into string lines (varchar) in SQL Firebird?

CODE SAMPLESDELPHI
Home›CODE SAMPLES›Convert Json to TFDMemTable

Convert Json to TFDMemTable

By admin
December 7, 2020
2584
0
Share:

When working (although I don’t like to do these things), you need to transfer the returned json data to the local DBGrid for display.

So I collected it and used XSuperJSON to convert the data into a memory table.

We convert the JSON array object ISuperArray returned from the request to FDM and then connect to the DataSet for display.

The function given below is the conversion function that I wrote roughly.

(*json Data conversion memory table*)
function JsonToDataSet2(JAry: ISuperArray; MDB: TFDMemTable):Boolean;
begin
Result:= True;
try
JSONToDataSet(jAry,MDB);
MDB.Post;
except
Result:= False;
end;
end;

 

The above can be displayed after adding fields to the memory table

The following is the automatically generated field

(*Automatic memory table conversion
Only recognize integer and string, floating point and date json will be displayed as string*)

function JsonToFDMDataSet(JAry: ISuperArray; MDB: TFDMemTable):Boolean;
var
JO: ISuperObject;
K: string;
begin
Result:= JAry.Length > 0;
if Result then
begin
JO:= JAry.O[0];
MDB.Close;
if MDB.FieldDefs.Count > 0 then
MDB.FieldDefs.Clear;
while not JO.EoF do
begin
K:= JO.CurrentKey;
if JO.CurrentValue.DataType = dtInteger then
MDB.FieldDefs.Add(K, ftInteger, 0, False)
else
if JO.CurrentValue.DataType = dtFloat then
MDB.FieldDefs.Add(K,ftFloat,0,False)
else
MDB.FieldDefs.Add(K, ftString, 30, False);
JO.Next;
end;
MDB.CreateDataSet;
JSONToDataSet(JAry,mdb);
MDB.Post;
MDB.First;
end;
end;

Remember to reference the unit

XSuperJSON,
XDataToJson,
XSuperObject,
FireDAC.Comp.Client;

Tagsdelphidelphi FDMemTabledelphi jsonFDMemTablejsonjson to FDMemTable
Previous Article

Socket error codes and possible problems

Next Article

TMS WEB CORE designed page layout directly ...

0
Shares
  • 0
  • +
  • 0
  • 0
  • 0
  • 0

admin

Related articles More from author

  • DELPHIFIREMONKEY

    Delphi Android integrates ZXing Barcode

    October 31, 2020
    By admin
  • CODE SAMPLESDELPHI

    UniGUI’s forms and modules

    November 9, 2020
    By admin
  • DELPHI

    Tending to the Problem of the Missing dbxConnections.ini File

    October 1, 2020
    By admin
  • CODE SAMPLESDELPHI

    Use LockBox does encryption and decryption

    January 2, 2021
    By admin
  • CODE SAMPLESDELPHIFIREMONKEY

    Delphi implementation software version verification code

    December 10, 2020
    By admin
  • CODE SAMPLESDELPHI

    How to put a DateTimePicker in the DBGrid?

    January 3, 2021
    By admin

Leave a reply Cancel reply

You may interested

  • CODE SAMPLESDELPHIFIREMONKEY

    Delphi recognizes the battery level of an Android device

  • CODE SAMPLESDELPHI

    UniGUI special objects

  • CODE SAMPLESDELPHI

    Talk about the application of SSL protocol in Delphi [transfer]

  • LATEST REVIEWS

  • TOP REVIEWS

Timeline

  • January 27, 2021

    How to add a server application written in UNIGUI to startup?

  • January 27, 2021

    UniGUI Expiry Link Anonymizer

  • January 26, 2021

    UniGUI Add CAPTCHA to the WEB project

  • January 26, 2021

    UniGui. Unique hybrid of Delphi and JS

  • January 13, 2021

    How to transform a blob field into string lines (varchar) in SQL Firebird?

Latest Comments

Find us on Facebook

Follow Us on Instagram

logo

Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.

About us

  • 660 Pennsylvania Avenue Southeast #100 Washington, DC 20003
  • 0123456789
  • adsdelphi@gmail.com
  • Recent

  • Popular

  • Comments

  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • UniGUI Expiry Link Anonymizer

    By admin
    January 27, 2021
  • UniGUI Add CAPTCHA to the WEB project

    By admin
    January 26, 2021
  • UniGui. Unique hybrid of Delphi and JS

    By admin
    January 26, 2021
  • How to add a server application written in UNIGUI to startup?

    By admin
    January 27, 2021
  • Amazing Cross Platform Email App Sample In Delphi 10.4.1 FireMonkey For Android And IOS

    By admin
    August 13, 2020
  • Critical Update Available For Delphi FireMonkey 10.4.1 On Android, IOS, OSX, Windows, And Linux

    By admin
    September 4, 2020
  • Setting up the IDE for your first Android Application in Delphi

    By admin
    September 7, 2020

Follow us

Find us on Facebook

© Copyright Delphifan Forum. All rights reserved.