> For the complete documentation index, see [llms.txt](https://water-1.gitbook.io/requests/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://water-1.gitbook.io/requests/json-ge-shi-de-cao-zuo.md).

# JSON格式的操作

> Python 本身有提供完善的json格式操作的函式
>
> 不過幾個容易誤解的json問題 在這裡先行列出

* JSON是字串 不是物件或任何可以直接取用的格式

```
一般我們收到的JSON格式是長這樣
{"keyword":"value"}
但從網頁上取得 或是從文件裡取得 的時候都還只是字串
我們必須先透過 函式將它轉換為物件
例：
JSON字串 = '{"keyword":"value"}'
物件 = json.loads(JSON字串)
這個時候 你才可以對物件進行操作
```

* JSON只會有兩個型

```
大括號 【{}】 所包起來的值 在python 表示為 dict 
中括號 【[]】 所包起來的值 在python 表示為 array
```

* JSON在python的函式常用的為

```
json.dumps() => 將物件 或 陣列轉為json字串
json.loads() => 將json字串 轉為 物件 或陣列
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://water-1.gitbook.io/requests/json-ge-shi-de-cao-zuo.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
