用户:随机昵称6查看:1 回复:3 评论:1 创建时间:2019-08-17T10:52:48
【作品展示】

【作品介绍】
这个代码主要介绍了json的几个基本用处,想写入哪一个类型的就把写入那个类型的代码前面的注释取消就行了。
【作品源代码】
import json
a=123 #数字
b=[1,2,3,4,5] #字符串
c={"a":"1"} #字典
#json写入
# with open('data.json', 'w') as f: #写入变量a(数字类型)
# json.dump(a,f)
# with open('data.json', 'w') as f: #写入变量b(字符串类型)
# json.dump(b, f)
with open('data.json', 'w') as f: #写入变量c(字典类型)
json.dump(c, f)
#json读取
with open('data.json','r') as f:
content=json.load(f)
print(content) #打印内容
print(type(content))#打印数据类型
【提示】
部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:
https://python.codemao.cn