【问题标题】:Getting a single Json value in python在python中获取单个Json值
【发布时间】:2022-01-14 21:03:11
【问题描述】:

我有这个 API 响应,我想获取一些值并将它们存储为 Python BOT 的变量,例如“floor_price”(我想要它后面的整数),但由于某种原因,它无法正常工作,它一直给我错误,但是当我使用“统计”尝试它时,它可以工作并提供一切。

APIhttps://api.opensea.io/api/v1/collection/ogcats-harvest-galaxy/stats

url = "https://api.opensea.io/api/v1/collection/ogcats-harvest-galaxy/stats"

 headers = {"Accept": "application/json"}

response = requests.request("GET", url)
json_response = response.json()
 floor= json_response['floor_price']

请帮忙:)

【问题讨论】:

  • 如果该 sn-p 正是程序运行的方式,您将需要删除标题和地板的单个空格缩进
  • 肯定是 json_response["stats"]["floor_price"] 不?
  • @kindall 谢谢你,很有魅力。

标签: python json api opensea


【解决方案1】:
url = "https://api.opensea.io/api/v1/collection/ogcats-harvest-galaxy/stats"

headers = {"Accept": "application/json"}

response = requests.request("GET", url)
json_response = response.json()
floor= json_response['stats']['floor_price']

学分:@kindall

【讨论】:

  • 从 kindall 得到它,只是作为答案重新发布,以便更容易找到。如果其他人有同样的问题
猜你喜欢
  • 1970-01-01
  • 2021-04-21
  • 1970-01-01
  • 2018-04-10
  • 1970-01-01
  • 1970-01-01
  • 2015-03-31
  • 1970-01-01
相关资源
最近更新 更多