labels.append(self.class_dict[obj["name"]]) TypeError: string indices must be integers

json文件里面有“name”对应的val值是整数,想问下大家为啥传不过来json文件里的val值,是我解析json文件出问题了吗。


json_file = './pascal_voc_classes.json'
        assert os.path.exists(json_file), "{} file not exist.".format(json_file)
        with open(json_file, 'r') as f:
            f = demjson.encode(json_file)
            self.class_dict = json.loads(f)

 labels.append(self.class_dict[obj["name"]])

Original Traceback (most recent call last):
  File "F:\Anaconda\lib\site-packages\torch\utils\data\_utils\worker.py", line 198, in _worker_loop
    data = fetcher.fetch(index)
  File "F:\Anaconda\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "F:\Anaconda\lib\site-packages\torch\utils\data\_utils\fetch.py", line 44, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "G:\code\deep-learning-for-image-processing-master\pytorch_object_detection\faster_rcnn\my_dataset.py", line 97, in __getitem__
    labels.append(self.class_dict[obj["name"]])
TypeError: string indices must be integers

这是我的json文件:

img