> ## 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>

## 其他资源

以下文章是使用 jsonOpen 操作的真实用例：

* <a href="https://community.cdata.com/cdata-arc-48/dynamic-bearer-token-authorization-in-the-rest-connector-220?tid=220&fid=48" target="_blank">REST 端口中的动态 Bearer Token 授权</a>
