这是我的代码
j = """
{
"kind": "youtube#videoListResponse",
"items": [
{
"kind": "youtube#video",
"id": "IEEhzQoKtQU",
"statistics": {
"viewCount": "171938",
"likeCount": "5856",
"dislikeCount": "38",
"favoriteCount": "0",
"commentCount": "368"
}
}
],
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
}
}
"""
js = json.loads(j)
js = js["items"]
js = js["statistics"]
print(js["viewCount"])
我是 json 的新手,我试图从这个 json 字符串中检索 viewCount。但是每次我运行代码时都会收到此错误:
js = js["statistics"]
TypeError: list indices must be integers or slices, not str
有没有人有办法解决吗?
扬帆大鱼
相关分类