[英]Python filter Json requests.get result
嗨,大家好,我试图弄清楚如何过滤从阅读json中得到的结果。
我正在使用requests.get
https://www.cryptopia.co.nz/api/GetMarket/5662
返回:
{
"Success": true,
"Message": null,
"Data": {
"TradePairId": 5662,
"Label": "ETN/BTC",
"AskPrice": 0.00000493,
"BidPrice": 0.00000492,
"Low": 0.00000488,
"High": 0.00000575,
"Volume": 12863643.12913574,
"LastPrice": 0.00000492,
"BuyVolume": 281607744.12368695,
"SellVolume": 12716829.67763919,
"Change": -10.38,
"Open": 0.00000549,
"Close": 0.00000492,
"BaseVolume": 68.58095479,
"BuyBaseVolume": 86.33526192,
"SellBaseVolume": 448023579.52566910
},
"Error": null
}
例如,我想做的只是提取2个字段。
假设说“标签”和“问价”
这是我的代码:
r = requests.get('https://www.cryptopia.co.nz/api/GetMarket/5662')
json_data = r.json()
我需要从这里知道该怎么办
非常感谢您的帮助:)
在响应上调用的json
方法返回一个python dict
,因此您可以通过调用json_data.get(u'Data').get(u'Label')
或json_data[u'Data'][u'Label']
来访问属性。
这会让你俩
json_data['Data']['Label']
json_data['Data']['AskPrice']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.