製品をチェック

JSON ODBC Driver の30日間無償トライアルをダウンロード

 30日間の無償トライアルへ

製品の詳細

JSON アイコン JSON ODBC Driver 相談したい

JSON ODBC Driver は、ODBC 接続をサポートする様々なアプリケーションからJSON Web サービスへの接続を実現するパワフルなツールです.

標準データベースにアクセスするときと同感覚でJSON サービスにアクセスし、標準ODBC Driver インターフェースを通じて読み出し、書き込み、更新が可能に。

Build a Simple VCL Application for JSON Services

How to build a simple VCL Application to view JSON services in RAD Studio using the CData ODBC Driver for JSON.

最終更新日:2023-06-12

Embarcadero RAD Studio provides a development environment for Delphi and C++Builder applications. With the CData ODBC Driver for JSON, you gain access to live JSON services within RAD Studio, abstracting the data into tables, views, and stored procedures that can be used to retrieve and update JSON services. This article will walk through connecting to JSON and creating a simple VCL application with the Form Designer.

Create a Connection to JSON Services

If you have not already, first specify connection properties in an ODBC DSN (data source name). This is the last step of the driver installation. You can use the Microsoft ODBC Data Source Administrator to create and configure ODBC DSNs.

データソースへの認証については、ヘルプドキュメントの「はじめに」を参照してください。CData 製品は、JSON API を双方向データベーステーブルとして、JSON ファイルを読み取り専用ビュー(ローカル ファイル、一般的なクラウドサービスに保存されているファイル、FTP サーバー)としてモデル化します。HTTP Basic、Digest、NTLM、OAuth、FTP などの主要な認証スキームがサポートされています。詳細はヘルプドキュメントの「はじめに」を参照してください。

URI を設定して認証値を入力したら、DataModel を設定してデータ表現とデータ構造をより厳密に一致させます。

DataModel プロパティは、データをどのようにテーブルに表現するかを制御するプロパティで、次の基本設定を切り替えます。

  • Document(デフォルト):JSON データのトップレベルのドキュメントビューをモデル化します。CData 製品 は、ネストされたオブジェクト配列を集約されたJSON オブジェクトとして返します。
  • FlattenedDocuments:ネストされた配列オブジェクトと親オブジェクトを、単一テーブルに暗黙的に結合します。
  • Relational:階層データから個々の関連テーブルを返します。テーブルには、親ドキュメントにリンクする主キーと外部キーが含まれています。

リレーショナル表現の設定についての詳細は、ヘルプドキュメントの「JSON データのモデリング」を参照してください。また、以下の例で使用されているサンプルデータも確認できます。データには人や所有する車、それらの車に行われたさまざまなメンテナンスサービスのエントリが含まれています。

Amazon S3 内のJSON への接続

URI をバケット内のJSON ドキュメントに設定します。さらに、次のプロパティを設定して認証します。

  • AWSAccessKey:AWS アクセスキー(username)に設定。
  • AWSSecretKey:AWS シークレットキーに設定。

Box 内のJSON への接続

URI をJSON ファイルへのパスに設定します。Box へ認証するには、OAuth 認証標準を使います。 認証方法については、Box への接続 を参照してください。

Dropbox 内のJSON への接続

URI をJSON ファイルへのパスに設定します。Dropbox へ認証するには、OAuth 認証標準を使います。 認証方法については、Dropbox への接続 を参照してください。ユーザーアカウントまたはサービスアカウントで認証できます。ユーザーアカウントフローでは、以下の接続文字列で示すように、ユーザー資格情報の接続プロパティを設定する必要はありません。 URI=dropbox://folder1/file.json; InitiateOAuth=GETANDREFRESH; OAuthClientId=oauthclientid1; OAuthClientSecret=oauthcliensecret1; CallbackUrl=http://localhost:12345;

SharePoint Online SOAP 内のJSON への接続

URI をJSON ファイルを含むドキュメントライブラリに設定します。認証するには、User、Password、およびStorageBaseURL を設定します。

SharePoint Online REST 内のJSON への接続

URI をJSON ファイルを含むドキュメントライブラリに設定します。StorageBaseURL は任意です。指定しない場合、ドライバーはルートドライブで動作します。 認証するには、OAuth 認証標準を使用します。

FTP 内のJSON への接続

URI をJSON ファイルへのパスが付いたサーバーのアドレスに設定します。認証するには、User およびPassword を設定します。

Google Drive 内のJSON への接続

デスクトップアプリケーションからのGoogle への認証には、InitiateOAuth をGETANDREFRESH に設定して、接続してください。詳細はドキュメントの「Google Drive への接続」を参照してください。

You can then follow the steps below to use the Data Explorer to create a FireDAC connection to JSON services.

  1. In a new VCL Forms application, expand the FireDAC node in the Data Explorer.
  2. Right-click the ODBC Data Source node in the Data Explorer.
  3. Click Add New Connection.
  4. Enter a name for the connection.
  5. In the FireDAC Connection Editor that appears, set the DataSource property to the name of the ODBC DSN for JSON.

Create VCL Applications with Connectivity to JSON Services

Follow the procedure below to start executing queries to JSON services from a simple VCL application that displays the results of a query in a grid.

  1. Drop a TFDConnection component onto the form and set the following properties:

    • ConnectionDefName: Select the FireDAC connection to JSON services.
    • Connected: Select True from the menu and, in the dialog that appears, enter your credentials.
  2. Drop a TFDQuery component onto the form and set the properties below:

    • Connection: Set this property to the TFDConnection component, if this component is not already specified.
    • SQL: Click the button in the SQL property and enter a query. For example:

      SELECT [people].[personal.age] AS age, [people].[personal.gender] AS gender, [people].[personal.name.first] AS first_name, [people].[personal.name.last] AS last_name, [vehicles].[model], FROM [people] JOIN [vehicles] ON [people].[_id] = [vehicles].[people_id]
    • Active: Set this property to true.
  3. Drop a TDataSource component onto the form and set the following property:

    • DataSet: In the menu for this property, select the name of the TFDQuery component.
  4. Drop a TDBGrid control onto the form and set the following property:

    • DataSource: Select the name of the TDataSource.
  5. Drop a TFDGUIxWaitCursor onto the form — this is required to avoid a run-time error.

You now have an executable application that displays the results of the SQL Query set in the TFDQuery object.

Related Articles

Below you can find other articles for using the CData ODBC Driver with RAD Studio, Delphi, and C++ Builder.

関連コンテンツ

トライアル・お問い合わせ

30日間無償トライアルで、CData のリアルタイムデータ連携をフルにお試しいただけます。記事や製品についてのご質問があればお気軽にお問い合わせください。