2 回答

TA贡献1848条经验 获得超2个赞
您的代码正在做它应该做的事情,如果您想要 json 的某个部分,只需访问它。
import requests
url = "https://api.iextrading.com/1.0/stock/aapl/stats"
response = requests.get(url).json()
print(response['float'])
>4705473314
print(response['symbol'])
>'AAPL'
print(response['symbol'], response['float'])
要存储response在 json 文件中,我们可以执行以下操作
import json
filename='resp.json'
with open(filename, 'w') as outfile:
json.dump(response, outfile, indent=4)

TA贡献1810条经验 获得超5个赞
你可以把它当作一本字典。response['float']会给你浮动。对于任何键也是如此。
import requests
url = "https://api.iextrading.com/1.0/stock/aapl/stats"
response = requests.get(url).json()
print (response['float'])
print(response['symbol'])
输出
4705473314
AAPL
添加回答
举报