【发布时间】:2019-02-21 00:13:37
【问题描述】:
我已压缩 JSON 文件,从 Auth0 导出,内容如下:
{"Id":"auth0|59bdb71ea714e32e8a6662fd","Nickname":"autoqa.krd0xj","Name":"autoqa.krd0xj@marketingg2.com","Email":"autoqa.krd0xj@marketingg2.com","Email Verified":false,"Connection":"Username-Password-Authentication","Created At":"2017-09-16T23:43:27.002Z","Updated At":"2017-09-16T23:43:27.490Z"},
{"Id":"auth0|18142559","Nickname":"moharvey","Name":"moharvey@ymail.com","Email":"moharvey@ymail.com","Connection":"Username-Password-Authentication","Created At":"2017-08-31T18:55:02.688Z","Updated At":"2017-08-31T19:01:36.994Z"}
我尝试使用此代码:
import json
import gzip
with gzip.GzipFile("file.gz", 'r') as fin:
json_bytes = fin.read()
json_str = json_bytes.decode('utf-8')
data = json.loads(json_str)
print(data)
但是上面的代码不能读取这个文件。 如何读取此文件中的所有数据?可以给点建议吗?
【问题讨论】:
标签: json python-3.x file