python3.常用模块学习-序列化模块-jason

jason:
只支持 str, int , tuple, list ,dict.
可以夸语言
pickle
支持python所有的数据类型
但是只能在python里使用,不能夸语言
操作如下:
import json
data = {
‘rol’ : [
{‘test1’:’first’,’test2’:’second’,’test3’:’thred’},
{‘line1’:’a’,’line2’:’b’,’line3’:’c’},
]
}
print(data)
写入文件
f = open(“test.json”,”w”)
json.dump(data,f)
==============
读取文件
f = open(“test.json”,”r”)
d = json.load(f)
print(d[‘rol’])

猜你喜欢

转载自blog.csdn.net/ciscosong/article/details/81322538