简体   繁体   English

JSONDecodeError:期望值 Python

[英]JSONDecodeError: Expecting value Python

The error "expecting value" is occurring when I'm trying to read a json file which I have created myself.当我试图读取我自己创建的 json 文件时,出现错误“expecting value”。 The weird thing is that this used to work.奇怪的是,这曾经有效。 I was working on another project in between and did some updates to conda and now I'm getting the error.我正在从事另一个项目,并对 conda 进行了一些更新,现在我收到了错误。 I've searched and found similar questions but none that have been applicable in my case.我搜索并发现了类似的问题,但没有一个适用于我的情况。

This is what I'm doing right now:这就是我现在正在做的事情:

def show_json(filepath):
        with open("/Users/human/Doc/PYTHON/bn/bread/"+filepath) as f:
            k = json.load(f)
            return k

state_d = show_json("states_json.json")

Here is the error traceback:这是错误回溯:


  File "/Users/human/PYTHON/SPYDER/bn/bread/main_.py", line 55, in <module>
    state_d=show_json("states_json.json")

  File "/Users/human/PYTHON/SPYDER/bn/bread/main_.py", line 48, in show_json
    k = json.load(f)

  File "/Users/human/opt/anaconda3/envs/futures/lib/python3.8/json/__init__.py", line 293, in load
    return loads(fp.read(),

  File "/Users/human/opt/anaconda3/envs/futures/lib/python3.8/json/__init__.py", line 357, in loads
    return _default_decoder.decode(s)

  File "/Users/human/opt/anaconda3/envs/futures/lib/python3.8/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())

  File "/Users/human/opt/anaconda3/envs/futures/lib/python3.8/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None

JSONDecodeError: Expecting value

And this is what the json file looks like:这就是 json 文件的样子:

{"_state_one_":None,"_state_two_":None,"_state_three_":None,"_state_four_":None}

Could something have happened while updating some libraries and packages or am I just doing something wrong code-wise?更新某些库和包时可能发生了什么事,还是我只是在代码方面做错了什么?

Your JSON file is simply not compliant to the JSON specifications .您的 JSON 文件根本不符合JSON 规范 Shortly put, null should be used instead of None简而言之,应该使用null而不是None

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM