首页 > 解决方案 > 将多个列表写入 JSON 文件

问题描述

我可以将单个列表存储到 json 文件中以供以后使用。您如何将多个列表存储到 json 文件中。假设我想将用户名添加到文件中,并将用户名 + '@gmail.com" 作为另一个列表添加到同一个文件中。稍后您将如何从 json 文件中访问这两个列表?

import json
username = johnsmith91
storelist = []
storelist.append(username)
with open('username.json', 'a') as outfile:
    json.dump(storelist, outfile)

标签: pythonjson

解决方案


推荐阅读