> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kasoftware.com/llms.txt
> Use this file to discover all available pages before exploring further.

# jsonOpen

> 從 URI 或靜態文字為 JSON 資料建立可讀控制代碼，供後續操作使用。

為來自 URI 或靜態文字的 JSON 資料建立可讀控制代碼。 當需要讀取靜態 JSON 資料、公共 URI 中的 JSON 資料或其他運算器輸出中的 JSON 資料時，此運算器非常有用。

## 必需的參數

* 無

## 可選的參數

* **uri**：JSON 檔案 URI（例如 `http://mydomain.com/resources/somedata.json` 或 `/tmp/myfile.json`）。
* **text**：JSON 文字。 這可以是在 ArcScript 屬性上設定的靜態 JSON，也可以是指令碼中先前運算器的輸出（例如 http 運算器之一的 `[http:content]` 輸出屬性。）請參閱下面的範例。

## 輸出屬性

* **handle**：對 JSON 資料的可讀控制代碼引用。 該控制代碼可供後續運算器使用（參見下面的範例）。
* **warning#**：可讀JSON控制代碼的警告陣列。

## 範例

下面是一個使用 jsonOpen 為某些靜態 JSON 文字建立控制代碼，然後將該控制代碼傳遞給另一個運算器的範例（在本例中，第二個運算器是 jsonDOMGet）：

```xml theme={null}
<!-- Setting a static JSON text -->
<arc:set attr="json.text" value='{"hello": "world","settings": {"foo": "bar"}}' />
<arc:call op="jsonOpen" in="json" out="output" >
  <!-- Setting the json handle as an attribute on a new item that is passed into a second operation  -->
  <arc:set attr="json2.handle" value="[output.handle]" />
  <arc:set attr="json2.map:value1" value="/json/settings/foo" />
  <arc:call op="jsonDOMGet" in="json2" out="output2" >
    <!-- Here is where you can execute additional script for the operation that is using the handle -->
    <!-- This example logs the value of the foo setting from the json text to the application log, which is "bar" -->
    <arc:set attr="_log.info" value="[output2.value1]" />
  </arc:call>
  <arc:finally>
    <!-- Close the json handle -->
    <arc:call op="jsonClose" in="json2" />
  </arc:finally>
</arc:call>
```

<Note>使用 jsonOpen 時，請確保在指令碼末尾使用相應的 [jsonClose](./op-json-close) 運算器來關閉控制代碼，以避免透過開啟的控制代碼洩漏記憶體。</Note>

## 其他資源
