在此处输入图像描述我使用 tweepy streamer API 收集了 15,000 条阿拉伯语推文用于研究目的。推文保存在 37 个 JSON 文件中,最后复制到一个 JSON 文件中。我正在尝试使用此脚本将其转换为 CSV:https ://github.com/HMukdadi/json-csv-converter
但我不断收到
“加载文件时出错...退出:额外数据:第 3 行第 1 列(字符7478)“
另外,我是一名语言学家,我没有扎实的编程背景:)。
1 回答
0
这是正常的,因为 json 文件包含许多应该在 JSON 数组或父 json 对象中的 json 对象。
如果您愿意,请发布 2 或 3 行,我会为您编写一个接受您的输入类型的脚本,或者:在末尾添加 [at the beginning ],并且在每个 } 之后,除了最后一个,脚本将为您工作
此脚本将您的 json 文件(类似于示例)转换为有效的 json 数组,该数组将与 git repo 中的脚本一起使用(已测试)
import sys
print("[")
with open(sys.argv[1]) as files:
lines=files.readlines()
for line in lines:
if(line!="\n"):
print(line)
else:
print(",")
files.close()
print("]")
执行它:
python3 file.py [yourJsonFile] >> newJsonFile.json
然后使用 newJsonFile.json 执行 json-csv-converter.py
只需执行脚本:
然后执行 json-csv-converter.py :
于 2019-11-10T12:24:22.940 回答



