Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python/JSON-TypeError:列表索引必须是整数或片,而不是str_Python_Json - Fatal编程技术网

Python/JSON-TypeError:列表索引必须是整数或片,而不是str

Python/JSON-TypeError:列表索引必须是整数或片,而不是str,python,json,Python,Json,我正在尝试从JSON数据中获取matchID,但是,得到了下面的TypeError。有人可以在这里建议解决方案吗 网址: 错误: TypeError:列表索引必须是整数或片,而不是str 提前感谢。这是因为data是一个json列表。因此,您需要: for d in data: matchID = d['matchID'] print (matchID) 明白了。谢谢你的回答。 for d in data: matchID = d['matchID'] pr

我正在尝试从JSON数据中获取matchID,但是,得到了下面的TypeError。有人可以在这里建议解决方案吗

网址:

错误: TypeError:列表索引必须是整数或片,而不是str


提前感谢。

这是因为
data
是一个json列表。因此,您需要:

for d in data: 
    matchID = d['matchID']
    print (matchID)

明白了。谢谢你的回答。
for d in data: 
    matchID = d['matchID']
    print (matchID)