如何访问dict Python

如何访问dict Python,python,dictionary,Python,Dictionary,如果我打印(response[“response”])我会得到下面的代码,但我只想打印“currency\u code”的每个值,我需要做什么 { "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374", "balances": [ { "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374", "currency_code": "FEST", "

如果我打印(response[“response”])我会得到下面的代码,但我只想打印
“currency\u code”
的每个值,我需要做什么

{
  "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
  "balances": [
    {
      "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
      "currency_code": "FEST",
      "change": "0.0",
      "available": "350.55778445",
      "locked": "0.0",
      "sequence": 8256,
      "time": "2020-01-15T17:35:04.435Z"
    },
    {
      "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
      "currency_code": "BTC",
      "change": "0.0",
      "available": "0.000002444748",
      "locked": "0.0",
      "sequence": 8241,
      "time": "2020-01-14T23:30:12.570Z"
    },
    {
      "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
      "currency_code": "ETH",
      "change": "0.3118",
      "available": "0.0",
      "locked": "0.0",
      "sequence": 8015,
      "time": "2020-01-13T06:59:06.443Z"
    },
    {
      "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
      "currency_code": "EUR",
      "change": "35.96096",
      "available": "49.63897609",
      "locked": "0.0",
      "sequence": 8256,
      "time": "2020-01-15T17:35:04.435Z"
    },
    {
      "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
      "currency_code": "MIOTA",
      "change": "15802.0",
      "available": "0.0",
      "locked": "0.0",
      "sequence": 8214,
      "time": "2020-01-14T23:00:11.357Z"
    },
    {
      "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
      "currency_code": "BAN",
      "change": "1106.0",
      "available": "0.06758229",
      "locked": "0.0",
      "sequence": 7986,
      "time": "2020-01-08T11:53:27.266Z"
    },
    {
      "account_id": "2b9e9aea-59e4-11e9-8c75-0a0e6623f374",
      "currency_code": "XRP",
      "change": "14157.0",
      "available": "0.0",
      "locked": "0.0",
      "sequence": 8238,
      "time": "2020-01-14T23:30:07.002Z"
    }
  ]
}

您需要从嵌套字典中取出每个元素,然后迭代字典列表并打印货币代码:

for bal in response.get('response').get('balances'):
    print(bal.get('currency_code', ''))

这样做:
对于response['response']['balances']:print(balance['currency\u code'])
。对于response['response'][“balances”]:TypeError:字符串索引必须是整数我忘了完全复制和粘贴print语句,我的打印错误(我的dict['currency\u code']))
for my_dict in response['responses']["balances"]:
  print(my_dict['currency_code'])