python - 为什么这个 json 文件会导致“预期 value”错误?

我正在尝试将文件加载为 JSON。

这是数据文件:

{"Title":"Assignment Checker",
 "Q1_Solution":10517,
 "Q2_Solution":12, 
 "Q3_Solution":52,
 "Q4_Solution":84,
 "Q5_Solution":50,
 "Q6_Solution":1971,
 "Q7_Solution":("Hip", "Flat", "Gambrel", "Mansard", "Shed", "Gable")}

这是失败的代码:

f = open("checkerData.json")
checkerData = json.load(f)
f.close()

我收到此错误:

JSONDecodeError: Expecting value: line 8 column 16 (char 166)

回答1

JSON 中的括号无效以表示列表(数组)。

修复 JSON 以改用 []

这是有效的:

{
  "Title": "Assignment Checker",
  "Q1_Solution": 10517,
  "Q2_Solution": 12,
  "Q3_Solution": 52,
  "Q4_Solution": 84,
  "Q5_Solution": 50,
  "Q6_Solution": 1971,
  "Q7_Solution": [
    "Hip",
    "Flat",
    "Gambrel",
    "Mansard",
    "Shed",
    "Gable"
  ]
}

相似文章