【发布时间】:2021-01-25 08:52:03
【问题描述】:
如何从带有原始长文本数据的 JSON 文件中加载数据?
我有一个包含新闻的大文件:
[body] 是我需要分析的新闻数据。
我试着这样读:
with open('file.json', 'r') as openfile:
# Reading from json file
dfnew = json.load(openfile)
openfile.close
但我得到一个错误:
Extra data: line 2 column 1 (char 1938)
也许你知道更好的方法,我怎样才能保存它,以便于阅读?
我使用以下代码从数据框创建了文件:
df.to_json('file.json', orient='records', lines=True)
【问题讨论】:
-
您拥有 JSON 行 格式的数据。你只需要自己解码每一行。
标签: python json python-3.x parsing