我收到此错误。我使用的是Python 3.5.0。 这是我的代码:
import json
import requests
from tqdm import tqdm
import os.path
r = requests.get("http://prod.ivtr-od.tpg.ch/v1/GetStops.json?key=d95be980-0830-11e5-a039-0002a5d5c51b")
path = "/Users/me/Desktop/JSON/"
pbar = tqdm(r.json()["stops"])
for x in pbar:
tree = {}
fileMON = open(path + x["stopCode"] + ".json", "r", encoding='utf8')
print(fileMON)
if "MON" in json.loads(fileMON()):
tree["MON"] = json.loads(fileMON())["MON"]
这是输出:
<_io.TextIOWrapper name='/Users/me/Desktop/JSON/31DCdeparts.json' mode='r' encoding='utf8'>
Traceback (most recent call last):
File "json.py", line 14, in <module>
tree["MON"] = json.loads(fileMON())["MON"]
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
我的JSON文件采用UTF8编码。有人可以帮帮我吗?