Get Data from a List of a dictonary

I got some data from a file:

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

Now I want to read out the cash from "MrDacom#9952". How can I do this? Things like this:

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

don't work.

3 answers

  • answered 2020-04-02 19:55 ritratt

    Your code data['MrDacom#9952']['cash'] does not work because data is a list.

    The right way to access it can be:

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

  • answered 2020-04-02 20:01 Gabip

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

  • answered 2020-04-02 20:05 Maxqueue

    Following will work

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