【发布时间】:2019-04-08 11:33:26
【问题描述】:
我有一个捕获以下 JSON 信息的 python 方法:
{'info': {'orderId': 5913316, 'clientOrderId': 'ME_dot', 'origQty': '0.02000000', 'trade': 'xxx', 'updateTime': xxx, 'side': 'BUY', 'timeInForce': 'GTC', 'status': 'FILLED', 'stopPrice': '0.0', 'time': xxx, 'isWorking': True, 'type': 'LIMIT', 'price': '506.10887700', 'executedQty': '0.02000000'}, 'lastTradeTimestamp': None, 'remaining': 0.0, 'fee': None, 'timestamp': x, 'symbol': 'xxx', 'trades': None, 'datetime': 'xxx, 'price': 0.108877, 'amount': 0.02, 'cost': 0.00217754, 'status': 'closed', 'type': 'limit', 'id': '59139516', 'filled': 0.02, 'side': 'buy'}
从中,我只需要捕获clientOrderId 和executedQty,所以我正在尝试以下操作:
id, q = (exchange.order_status(trading )['info']['clientOrderId'], ['info']['executedQty'])
带来这个问题:TypeError: list indices must be integers, not str
那么我怎样才能在同一行代码中捕获值?
【问题讨论】:
标签: json python-3.x error-handling