期望属性名称包含在内... ||无法打开json文件

时间:2019-03-15 15:16:00

标签: json python-3.x

当您尝试打开json文件时,出现此错误

    Traceback (most recent call last):
  File "C:\Users\vlad0\AppData\Roaming\Python\Python36\site-packages\discord\client.py", line 227, in _run_event
    await coro(*args, **kwargs)
  File "c:\Users\vlad0\Desktop\bot\bot.py", line 577, in on_message
    info = json.load(open('servers/'+str(server)+'/reports/'+str(user["MaxRepID"])+'/info.json'))
  File "C:\py36\lib\json\__init__.py", line 299, in load
    parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
  File "C:\py36\lib\json\__init__.py", line 354, in loads
    return _default_decoder.decode(s)
  File "C:\py36\lib\json\decoder.py", line 339, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\py36\lib\json\decoder.py", line 355, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 18 (char 19)

这是打开它的代码(路径正确)

info = json.load(open('servers/'+str(server)+'/reports/'+str(user["MaxRepID"])+'/info.json'))

json文件

{
  "Channel": "", /* ID */
  "Created": "", /* Date */
  "Author": "", /* who created */
  "Is_closed": "False",
  "Is_open": "False",
  "Is_deleted": "False"
}

如您所见,不会跳过双括号,但是有什么错误吗?

1 个答案:

答案 0 :(得分:0)

我认为JSON文件中不允许使用C样式的注释(至少Python JSON解析器不允许它们),因此请尝试将其删除。

编辑:如@Marcus在评论中所建议,this question具有一些用于解析带有注释的JSON文件的选项,包括使用诸如jsminjstyleson和{ {3}},它们都在PyPI上,可以通过pip安装。