JSON 是 JavaScript Object Notation 的缩写,它是一种数据交换格式。
在JSON中,允许的值就这6种:
- number:数字类型;
- boolean:true 或 false;
- string:字符串类型;
- null:空值;
- array:数组类型;
- object:对象,使用{ }表示的类型。
python中的json模块
json 模块提供了一种很简单的方式来编码和解码JSON数据。 其中两个主要的函数是 json.dumps()
和 json.loads()
。
python数据转化为JSON数据 —— dumps
import json
data = {
'name':'Tony',
'age':18,
'gender':'male'
}
print(type(data)) # <class 'dict'>
j_data = json.dumps(data