# JSONデータサービスの使用

## JSONデータサービスの使用

### e-FormからJSON文字列を取得

1. `membership-odiparam.ozr` を`membership-jsonset.ozr` にコピーし、`membership-jsonset.ozr`

   ファイルを開きます。
2. フォームをプレビューし、入力フィールドを入力します。
3. ビューアの右上にある**Etc** アイコン(<img src="/files/-Lyc-d7T4pJDxi1XKZFi" alt="" data-size="line">)をクリックして”**入力データコピー (json)”**&#x3092;選択します。
4. メモ帳を開き、クリップボードの文字列を貼り付けて、テキストファイル（`jsonset.txt`）として保存します。

### JSONデータサービスの作成

![](/files/-Lyaw41CoA4P2hSpqT5T)

1. データ情報タブで**DataService**を右クリックし&#x3066;**”JSONデータセットの追加”**&#x3092;選択します。&#x20;
2. ”JSONデータセットの追加”ダイアログで**パス**をクリックし、デザインタイムのデータセットとランタイムデータセットに`jsonset.txt`ファイルを追加します。&#x20;
3. 必要ある場合、デフォルトのデータセット名の**JSON\_Set1**を変更します（例：**jsonset**に変更）。&#x20;
4. 画面の下段でJSONデータの文字セットが設定できます。&#x20;
5. データセット名を右クリックして**セットの構成**を選択します。
6. ルートノードの$記号を右クリックし、**基準JSONPATH指定**を選択します。
7. データセットに含めたいすべてのフィールド項目を選択し、**フィールドの追加**を選択します。
8. 画面の下部に追加されたフィールドが表示されます。**OK**をクリックします。
9. データ情報タブのDataService下の`jsonset`データセットにフィールドが追加されたことが確認できます。
10. `member`データセットの代わりにDataServiceの`jsonset` が使用できるようになりました。ODIの`membership`を削除し、`member`データセットフィールドのマッピングをすべて`jsonset`のDataServiceのマッピングに置き換えます。&#x20;
11. プレビューをします。`jsonset.txt`の値をフォームの入力コンポーネントに入力できます。

### JSONデータセットにデータを渡すためのパラメータの作成

1. アプリケーションからJSONデータを取得してフォームファイルに渡すには、先ず、OZFormParamの下に`jsondata`パラメータを追加する必要があります。&#x20;
2. その後、`jsondata`から`jsonset`にデータを渡す必要があります。&#x20;
3. `jsonset`を右クリックして**編集**を選択します。&#x20;
4. **ランタイムデータセットの適用方法**からパラメー&#x30BF;**(データ)**&#x3092;選択した後、**パラメータ...**&#x3092;クリックします。&#x20;
5. パラメータ設定ダイアログで**jsondata**パラメーターを選択します。&#x20;
6. **OK**を2回クリックします。
7. ファイルを保存します。

![](/files/-LxxlU_rw1niA6S7ZNqo)

## JSONデータをe-Formに送信

以下のようにアプリケーションからJSONデータをフォームファイルに渡すことができます。

{% hint style="warning" %}
JSON文字列についてはエスケープ処理が必要です。
{% endhint %}

```javascript
<script type="text/javascript" >
var serverUrl = "https://" + location.host;
var jsondata = "{\"memberNo\":\"1011\",\"photo\":\"\",\"firstName\":\"John\",\"lastName\":\"Kim\",\"yyyy\":\"1979\",\"mm\":\"09\",\"dd\":\"05\",\"gender\":\"M\",\"contactNo\":\"010-6369-7777\",\"email\":\"john.kim@forcs.com\",\"memberType\":\"Trial\",\"fromDate\":\"2019-12-24\",\"toDate\":\"2020-12-24\",\"cardType\":\"VISA\",\"cardHolder\":\"\",\"cardNo\":\"1111-2222-3333-4444\",\"cardExpMM\":\"11\",\"cardExpYY\":\"24\",\"agreeCheck\":\"N\",\"applicant\":\"John\",\"sign\":\"\",\"signDateTime\":\"signDateTime\"}";
function SetOZParamters_OZViewer(){
	var oz = document.getElementById("OZViewer");
	oz.sendToActionScript("information.debug", "true"); // viewer console
	oz.sendToActionScript("connection.servlet",serverUrl + "/oz/server");
	oz.sendToActionScript("connection.reportname","/eform/membership-jsonset.ozr");
	oz.sendToActionScript("connection.pcount", "1");
	oz.sendToActionScript("connection.args1", "jsondata=" + jsondata);
	oz.sendToActionScript("etcmenu.copyinputdata_json", "true"); // enable [Copy input data (json)] option in etc menu
	return true;
}
start_ozjs("OZViewer", serverUrl + "/oz/HTML5viewer/");
</script>
```

[Run example](https://demo.ozeform.io/oz/eform/membership-jsonset.html)

{% file src="/files/-M4I7PyQUQXQjJH0JER3" %}
membership-jsonset.zip
{% endfile %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://jp.ozeform.io/bjonbakkuappu/oz-viewer-study/jsondtasbisuno.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
