python学习-49 json模块
json模块
--------将任何类型都转换为json字符串
方法dumps
import json dic={"name":"abc"} data = json.dumps(dic) print(type(data),data)
运行结果:
<class 'str'> {"name": "abc"} Process finished with exit code 0
----对文件的操作
方法loads
import json f_read = open("a","r") data = json.loads(f_read.read()) print(data["name"])
运行结果:
abc
Process finished with exit code 0