Skip to content

Commit 45ccb76

Browse files
committed
add json Anchor
Change-Id: I211605e5e41f07cc856569dbece492d2175367f1
1 parent 6da7ada commit 45ccb76

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

content/json.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ print python_str.others[1]
9696

9797
在解码json的时候可以采用`pprint`来获得一个比较漂亮的输出,在编码json的时候也可以在`dumps()`函数里加上参数`indent=X`来缩进从而获得一个比较漂亮的输出。
9898

99-
2016-01-13 更新
99+
### 2016-01-13 更新
100100

101101
在 Python 中 eval 和 str(unicode) 的功能也可以做 json 数据格式的转化
102102

@@ -127,7 +127,7 @@ NameError: name 'false' is not defined
127127

128128
对于 json 数据格式的操作还是让专业的库来干吧。
129129

130-
2017-03-18 更新
130+
### 2017-03-18 更新
131131

132132
json 格式数据与 Python 中的 字典(dict) 并不完全一致,json 只能是双引号包围的字符串,而 Python 中的字符串可以用双引号也可以用单引号。
133133

@@ -156,21 +156,21 @@ JSONEncoder().encode({"foo": ["bar", "baz"]}) # 将字典格式转换为 json
156156
JSONDecoder().decode('{"foo": ["bar", "baz"]}') # 将 json 字符串转换为字典格式
157157
```
158158

159-
2017-10-22 更新
159+
### 2017-10-22 更新
160160

161161
json 和 dict 还有两个地方不一样
162162
- dict 在所有的键值对之后还可以有逗号,json 在所有的键值对最后没有逗号
163163
- dict 的键可以是数字,json 的键不能是数字,只能是字符串
164164

165-
2018-06-21
165+
### 2018-06-21
166166

167167
- `json.dumps(obj, indent=4)` 能够输出一个格式化的字符串,有换行有缩进。
168168
- `json.dumps(obj, separators=(',',':'))` 能够对输出字符串进行一个简单的压缩,取消空格.因为默认是 `(', ', ': ')`
169169
- `json.dumps(obj, ensure_ascii=False)` 能够输出 utf-8 格式的中文即可见的中文,而非 Unicode 格式的中文 `\uXXXX`
170170

171-
2020-09-09
171+
### 2020-09-09
172172

173-
正常的 json 字符串像这样 `{"price": 542.23, "name": "ACME", "shares": 100, "others": ["first thing", "second thing", "third thing"]}` 都是没问题的,但是如果在 json 对象中,key 或者 value 里存在控制字符,就会出现 `Invalid Control Character``ValueError`
173+
正常的 json 字符串像这样 `'{"price": 542.23, "name": "ACME", "shares": 100, "others": ["first thing", "second thing", "third thing"]}'` 都是没问题的,但是如果在 json 对象中,key 或者 value 里存在控制字符,就会出现 `Invalid Control Character``ValueError`
174174

175175
**什么是控制字符?**
176176
ACSII 码表,排名前三十二位和最后一位的字符就是控制字符,包括 `\t`, `\n`, `\r` 等。

0 commit comments

Comments
 (0)