# 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: 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://water-1.gitbook.io/requests/json-ge-shi-de-cao-zuo.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.
