Python——保存、读取json文件

分手后的思念是犯贱 2022-06-17 05:27 349阅读 0赞

python——保存、读取json文件

  1. file = open('test.json','w',encoding='utf-8')
  2. data1 = {'name':'john',"age":12}
  3. data2 = {'name':'merry',"age":13}
  4. data = [data1,data2]
  5. print(data)
  6. json.dump(data,file,ensure_ascii=False)
  7. file.close()
  8. file = open('test.json','r',encoding='utf-8')
  9. s = json.load(file)
  10. print (s[0]['name'])

发表评论

表情:
评论列表 (有 0 条评论,349人围观)

还没有评论,来说两句吧...

相关阅读