简体   繁体   English

json.decoder.JSONDecodeError:期望属性名称用双引号引起来:读取 json 时第 2 行第 1 列(char 2)?

[英]json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) when reading a json?

{
  "teams": {
    "sp": [
      {
        "k": {
          "attack": 3,
          "defense": 4
        },
        "s": {
          "attack": 3,
          "defense": 4
        },
        "b": {
          "attack": 3,
          "defense": 4
        },
        "h": {
          "attack": 3,
          "defense": 4
        },
        "r": {
          "attack": 3,
          "defense": 4
        },
        "l": {
          "attack": 4,
          "defense": 5
        }
      }
    ],
    "mu": [
      {
        "r": {
          "attack": 5,
          "defense": 6
        },
        "a": {
          "attack": 4,
          "defense": 3
        },
        "f": {
          "attack": 4,
          "defense": 3
        },
        "c": {
          "attack": 4,
          "defense": 3
        },
        "v": {
          "attack": 4,
          "defense": 2
        },
        "dg": {
          "attack": 4,
          "defense": 5
        }
      }
    ]
  }
}

Code代码

obj = [json.loads(line) for line in open('playerlist.json', 'r')]
print(obj)

the above json is player list and below is the python code I'm trying to read it with.上面的json是播放器列表,下面是我试图读取它的 python 代码。 when I run it it raise当我运行它时它会升高

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)

I've read its a formatting issue with the json but when I run it through a json formatted it says it is valid json .我已经阅读了它的json格式问题,但是当我通过json格式运行它时,它说它是有效的json

The issue is that you are trying to convert individual lines to json , you need to convert the all file at once问题是您正在尝试将单行转换为json ,您需要一次转换所有文件

with open('playerlist.json', 'r') as f:
    obj = json.load(f)

暂无
暂无

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

相关问题 json.decoder.JSONDecodeError:期望用双引号括起来的属性名称:第 2 行第 2 列(字符 3) - json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 2 (char 3) json.decoder.JSONDecodeError:期望用双引号括起来的属性名称:第 2 行第 1 列(字符 2) - json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) json.decoder.JSONDecodeError:期望值:,json.decoder.JSONDecodeError:期望属性名称用双引号引起来: - json.decoder.JSONDecodeError: Expecting value: , json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: 如何解决 instascrape 标头中的“json.decoder.JSONDecodeError:期望用双引号括起来的属性名称”? - How to resolve "json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes" in headers for instascrape? JSONDecodeError:需要用双引号括起来的属性名称:第 2 行第 6 列(字符 6) - JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 6 (char 6) JSONDecodeError:期望用双引号括起来的属性名称:第 1 行第 3 列(字符 2) - JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2) json.decoder.JSONDecodeError:期望值:第2行第1列(char 1)错误 - json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1) error 错误:json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - ERROR: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 奇怪的“json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)” - WEIRD "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM