![](/img/trans.png)
[英]How to get a specific data from a json file using python and index number
[英]how to get specific data from json file using python
这是我下面的代码
from pybit import HTTP
import json
session = HTTP("https://api.bybit.com",api_key=xxxx, api_secret=xxxx)
g=session.get_wallet_balance(coin="USDT")
data=json.dumps(g,indent=4)
print(data)
for result in data ['USDT']:
print(["equity"])
不断收到这样的类型错误
for result in data ['USDT']:
TypeError: string indices must be integers
data=json.dumps(g,indent=4)
这使用 JSON 格式将 dict g
序列化为字符串。 不要那样做!
实际上,您根本不需要import json
,因为pybit
已经解析了来自 HTTP 请求的 JSON 响应,因此您无需执行任何操作。 相反,您应该直接使用g
: g['USDT']
。 更好的是,只需将g
重命名为data
:
data = session.get_wallet_balance(coin="USDT")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.