Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/321.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
&引用;TypeError:JSON对象必须是str,而不是';字节'&引用;在Python 3.5中读取JSON_Python_Json_Python 2.7_Python 3.5 - Fatal编程技术网

&引用;TypeError:JSON对象必须是str,而不是';字节'&引用;在Python 3.5中读取JSON

&引用;TypeError:JSON对象必须是str,而不是';字节'&引用;在Python 3.5中读取JSON,python,json,python-2.7,python-3.5,Python,Json,Python 2.7,Python 3.5,我想运行以下代码,首先是为Python2.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

我想运行以下代码,首先是为Python2.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.load
之间有什么区别?我如何确定何时使用哪个呢?

open(f,“rb”)
更改为
open(f,“r”)
。rb标志用于读取字节。

打开的
“rb”
->
“r”
)中删除二进制模式。我不知道你为什么要把它放在那里。你可以把一个文件读成字符串而不是二进制模式。当我改变它时,它后面跟着一个错误:raise jsondecoderError(“期望值”,s,err.value)from None json.decoder.jsondecoderError:期望值:第1行第1列(char 0)使用json.loads加载字符串