Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- uses
- REST.Response.Adapter, System.JSON;
- procedure JsonToDataset(aDataset : TDataSet; aJSON : string);
- var
- JObj: TJSONArray;
- vConv : TCustomJSONDataSetAdapter;
- begin
- if (aJSON = EmptyStr) then
- begin
- Exit;
- end;
- JObj := TJSONObject.ParseJSONValue(aJSON) as TJSONArray;
- vConv := TCustomJSONDataSetAdapter.Create(Nil);
- try
- vConv.Dataset := aDataset;
- vConv.UpdateDataSet(JObj);
- finally
- vConv.Free;
- JObj.Free;
- end;
- end;
- //**************************************************************************************************************
- unit Unit1;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, FireDAC.Stan.Intf, FireDAC.Stan.Option,
- FireDAC.Stan.Param, FireDAC.Stan.Error, FireDAC.DatS, FireDAC.Phys.Intf,
- FireDAC.DApt.Intf, Vcl.StdCtrls, Data.DB, FireDAC.Comp.DataSet,
- FireDAC.Comp.Client, Vcl.Grids, Vcl.DBGrids, Datasnap.DBClient;
- type
- TForm1 = class(TForm)
- DBGrid1: TDBGrid;
- DataSource1: TDataSource;
- DBGrid2: TDBGrid;
- DataSource2: TDataSource;
- FDMemTable1: TFDMemTable;
- Button1: TButton;
- ClientDataSet1: TClientDataSet;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.dfm}
- uses
- REST.Response.Adapter, System.JSON;
- procedure JsonToDataset(aDataset : TDataSet; aJSON : string);
- var
- JObj: TJSONArray;
- vConv : TCustomJSONDataSetAdapter;
- begin
- if (aJSON = EmptyStr) then
- begin
- Exit;
- end;
- JObj := TJSONObject.ParseJSONValue(aJSON) as TJSONArray;
- vConv := TCustomJSONDataSetAdapter.Create(Nil);
- try
- vConv.Dataset := aDataset;
- vConv.UpdateDataSet(JObj);
- finally
- vConv.Free;
- JObj.Free;
- end;
- end;
- procedure TForm1.Button1Click(Sender: TObject);
- const
- MEU_JSON =
- '[{'+
- '"Titulo": "Ate que a sorte nos separe",'+
- '"duracao": "120 min"'+
- '}, {'+
- '"Titulo": "Matrix",'+
- '"duracao": "140 min"'+
- '}]';
- begin
- JsonToDataset(FDMemTable1, MEU_JSON);
- JsonToDataset(ClientDataSet1, MEU_JSON);
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement