Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.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
Python json.decoder.JSONDecodeError:额外数据:第1行第12列(字符11)_Python_Json - Fatal编程技术网

Python json.decoder.JSONDecodeError:额外数据:第1行第12列(字符11)

Python json.decoder.JSONDecodeError:额外数据:第1行第12列(字符11),python,json,Python,Json,我知道这看起来像这个网站上的一些其他问题,但这给了我一个错误,其他答案不适用,以下是加载文件的代码: with open("Accounts.json") as infile: one_char = infile.read(1) if one_char: accounts = json.load(infile) 和json文件: {"ch_1_comp": false, "ch_2_comp": fal

我知道这看起来像这个网站上的一些其他问题,但这给了我一个错误,其他答案不适用,以下是加载文件的代码:

with open("Accounts.json") as infile:
    one_char = infile.read(1)
    if one_char:
        accounts = json.load(infile)
和json文件:

{"ch_1_comp": false, "ch_2_comp": false, "ch_3_comp": false, "ch_4_comp": false, "ch_5_comp": false, "ch_6_comp": false}
尽管我没有两个数据集,但我仍然会出错,我也不知道为什么


谢谢你的帮助

执行infle.read1时,它将读取第一个字符,即“{”,并将指针放在Chu 1_comp中的双引号上。 直接加载json,然后捕获异常以处理文件为空的情况

with open("Accounts.json") as infile:
    try:
        accounts = json.load(infile)
    except json.decoder.JSONDecodeError:
        print("Invalid json")

为什么要读取文件开头的一个字符?这会将文件指针放在第二个字符上,json.load将开始从chu…开始解码,这显然是一个坏的json。你能解释一下你想做什么吗?对不起,我想看看文件是否为空,我不知道它会有任何效果,谢谢欧点!