簡體   English   中英

在 Python 中加載 JSON 文件時如何解決此錯誤

[英]How can I fix this error while loading a JSON File in Python

我正在嘗試在 python 中加載 JSON,但我不斷收到錯誤

import json

f = open('StudentJson.json', 'r')
data = json.load(f)

print(data.items())

錯誤

Traceback (most recent call last):
  File "c:\Users\Chinyere\Documents\Python\Openpyxl\students.py", line 4, in <module>
    data = json.load(f)
  File "C:\Users\Chinyere\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 
   293, in load
  return loads(fp.read(),
  File "C:\Users\Chinyere\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
 return _default_decoder.decode(s)
  File "C:\Users\Chinyere\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Chinyere\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
  raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

我該如何解決這個錯誤。

嘗試將您的 json 文件輸入到這樣的 json linting 服務中。 它應該突出顯示 json 文件有什么問題

https://jsonlint.com/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM