我在谷歌Colab工作。我使用json.load()方法从json文件创建字典。代码是:
import json
! wget -O train_set.json https://github.com/rslab-ntua/MSc_GBDA/blob/master/2020/Exercise_ML2/train_split.json
with open('train_set.json') as f:
train_set = json.load(f)我得到以下错误:
---------------------------------------------------------------------------
JSONDecodeError Traceback (most recent call last)
<ipython-input-20-1a34dc9ec442> in <module>()
4
5 with open('train_set.json') as f:
----> 6 train_set = json.load(f)
3 frames
/usr/lib/python3.7/json/decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 7 column 1 (char 6)json文件的前几行是:

为什么会出现此消息错误?
发布于 2021-06-15 01:49:22
您正在使用的url会将您带到包含所需数据的页面,但是数据位于不同的url中。将“blob”更改为“raw”
r = requests.get('https://github.com/rslab-ntua/MSc_GBDA/raw/master/2020/Exercise_ML2/train_split.json').json()
print(r)
['2750/River/River_2132.jpg',
'2750/HerbaceousVegetation/HerbaceousVegetation_868.jpg',
'2750/Highway/Highway_316.jpg',
'2750/Residential/Residential_2628.jpg',
'2750/Industrial/Industrial_1304.jpg',
'2750/AnnualCrop/AnnualCrop_1615.jpg',
'2750/SeaLake/SeaLake_1227.jpg',
'2750/SeaLake/SeaLake_677.jpg',
'2750/Forest/Forest_2496.jpg',
'2750/Forest/Forest_2532.jpg',....https://stackoverflow.com/questions/67974769
复制相似问题