我需要创建一个包含许多 json 的 json 文件,例如:{}{}{}。
我实际上可以创建该文件,但是当我尝试读取它时,出现此错误:
raise JSONDecodeError("Extra data", s, end)
JSONDecodeError: Extra data
有什么帮助吗?
# Create dictionaries
texto = ['a','b','c','d','e']
keys = ['id','klass','text']
datos = []
for i in range(0,5):
values = [str(i), str(0), texto[i]]
dictio = dict(zip(keys, values))
datos.append(dictio)
# Create the json
for my_dict in datos:
with open("test.json", 'a') as fp:
json.dump(my_dict,fp)
# Read the json:
data = []
with open("test.json") as f:
for line in f:
data.append(json.loads(line))
我期望一个格式为 {}{}{} 的 .json 文件,并在 python 中读取该文件。现在我有了这种格式的文件,但是当我尝试读取它时出现错误
JSONDecodeError("Extra data", s, end)