大家好,我想知道如何过滤我从json中得到的结果。
即时通信工具在url https://www.cryptopia.co.nz/api/GetMarket/5662使用requests.get
它返回:
{
"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个字段。
让我们说"Label“和"AskPrice”
下面是我的代码:
r = requests.get('https://www.cryptopia.co.nz/api/GetMarket/5662')
json_data = r.json()我需要知道从这里开始要做什么
我很感谢你们的帮助:)
发布于 2017-11-11 06:27:28
在响应上调用的json方法返回一个python dict,因此您可以通过调用json_data.get(u'Data').get(u'Label')或json_data[u'Data'][u'Label']来访问属性。
发布于 2017-11-11 06:32:22
这会让你们两个
json_data['Data']['Label']
json_data['Data']['AskPrice']https://stackoverflow.com/questions/47232039
复制相似问题