从JSON d访问多维数组有困难

2024-09-27 23:26:44 发布

您现在位置:Python中文网/ 问答频道 /正文

以下是相关的JSON数据:

{
  "result_index": 0,
  "results": [
    {
      "alternatives": [
        {
          "confidence": 0.994,
          "transcript": "thunderstorms could produce large hail isolated tornadoes and heavy rain "
        }
      ],
      "final": true
    }
  ]

}

下面是我如何尝试访问它

parsed = json.loads(data)
print(parsed['results']['alternatives']['transcript'])

这将导致以下错误:

TypeError: list indices must be integers or slices, not str

似乎results只是一个数组,其中只有一个条目是字符串,我对如何访问其中的单个元素有点困惑


Tags: 数据jsonindexresultparsedresultscouldlarge

热门问题