Convert Json to TFDMemTable

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;