从命令列表中获取数据

2024-09-30 04:41:21 发布

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

我从一个文件中得到了一些数据:

[
     {
       "Boodie#1932": [
         {
           "cash": 20,
           "lastHourly": "21$28"
         }
       ]
     }
      "MrDacom#9952": [
        {
          "cash": 20,
          "lastHourly": "21$28"
        }
      ]
    ]

现在我想读出“MrDacom#9952”中的现金。我该怎么做? 诸如此类:

data['MrDacom#9952']['cash']

不要工作


Tags: 文件数据datacash现金boodiemrdacomlasthourly
3条回答

以下步骤将起作用

data['MrDacom#9952'][0]['cash'] 

试试看:data[0]['MrDacom#9952'][0]['cash']

你的代码 data['MrDacom#9952']['cash'] 无法工作,因为data是一个列表

正确的访问方式可以是:

data[0]['MrDacom#9952'][0]['cash']

相关问题 更多 >

    热门问题