Sign in Join
Wiki copytemporary

fpjsondataset/pl

English · Polski

fpjsondataset jest to moduł fcl-db zawierający klasę zbioru danych (dataset) umożliwiającą uzyskanie dostępu do danych JSON w postaci prostych struktur tabel.

TJSONDataSet

TJSONDataSet jest to klasa zbioru danych (dataset) używana do obsługi danych w postaci tablic JSON.

Note: TJSONDataSet jest zawarty we Free Pascalu, ale nie jest widoczny w palecie komponentów Lazarusa.

Przykład

  1. Utwórz nowy projekt aplikacji
  2. Umieść siatkę DB na formularzu (DBGrid1)
  3. Umieść DataSource w formularzu (DataSource1)
  4. Połącz DBGrid1.Datasource z DataSource1
  5. Utwórz zbiór danych JSON za pomocą kodu
pascal
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, DBCtrls, DBGrids, DB,
  fpjson, fpjsondataset;

type

  TForm1 = class(TForm)
    DataSource1: TDataSource;
    DBGrid1: TDBGrid;
    procedure FormCreate(Sender: TObject);
  private
    JSONDataSet: TJSONDataSet;
  end;

var
  Form1: TForm1;

const
  // to są przykładowe dane JSON użyte w demo
  JSON_STRING = '['
    +'{"Author ID":"409-56-7008","Last Name":"Bennet","First Name":"Abraham","Active": False},'
    +'{"Author ID":"213-46-8915","Last Name":"Green","First Name":"Marjorie","Active": True}'
    +']';

implementation

{$R *.lfm}

procedure TForm1.FormCreate(Sender: TObject);
var
  data: TJSONArray;
begin
  // przeanalizuj ciąg JSON
  data := GetJSON(JSON_STRING) as TJSONArray;
  // utwórz nowy zestaw TJSONDataSet
  JSONDataSet := TJSONDataSet.Create(Self);
  // musisz ręcznie utworzyć FieldDefs
  // ftString wymaga określonej długości
  JSONDataSet.FieldDefs.Add('Author ID', ftString, 11, True);
  JSONDataSet.FieldDefs.Add('Last Name', ftString, 40);
  JSONDataSet.FieldDefs.Add('First Name', ftString, 20);
  JSONDataSet.FieldDefs.Add('Active', ftBoolean);
  // ustaw OwnsData na True, a dane JSON zostaną zniszczone, gdy zestaw danych zostanie zniszczony
  JSONDataSet.OwnsData := True;
  // dane JSON to tablica obiektów
  JSONDataSet.RowType := rtJSONObject;
  // przypisz dane JSON do zbioru danych
  JSONDataSet.Rows := data;
  // aktywuj zbiór danych
  JSONDataSet.Active := True;
  // przypisz zbiór danych do źródła danych
  DataSource1.DataSet := JSONDataSet;
end;

end.

From the Free Pascal wiki, page "fpjsondataset/pl", as it stood on 2022-10-04 after a change by Slawek, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 1, last changed by WikiArchive .

Edited on wiki.freepascal.org by 1 person, 2022

From the official wiki's backup of 26 May 2024: who edited this page there, and when. Edits made there after that date were not recorded, and the earlier versions are not shown here; the main page says why.

WhenWhoWhat changed
Slawektłumaczenie na j. polski

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.