【发布时间】:2017-11-01 16:08:47
【问题描述】:
我想运行以下代码,最初是为 Python 2.7 编写的,现在我想为 python3.5 运行。 以下是我的代码:
import json
import glob
read_files = glob.glob("*.json")
output_list = []
for f in read_files:
with open(f, "r") as infile:
output_list.append(json.load(infile))
with open("merged_file.json", "wb") as outfile:
json.dump(output_list, outfile)
但它一直给出以下错误:
raise JSONDecodeError("Expecting value", s, err.value) from
None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
json.load 和 json.loads 之间有什么区别,我如何确定何时使用哪个?
【问题讨论】:
-
删除
open("rb"->"r") 中的二进制模式。我不知道你为什么把它放在那里。 -
您可以将文件读取为字符串而不是二进制模式
标签: python json python-2.7 python-3.5