我正在尝试用 python 编写我的第一个 API 查询。我正在调用一个非常简单的数据集。 (http://api.open-notify.org/astros.json)。这会显示有关太空中人数的信息。
我可以返回号码,但我想尝试显示姓名。到目前为止,我有:
import requests
response = requests.get("http://api.open-notify.org/astros.json")
data = response.json()
print(data["number"])
如有任何帮助,我们将不胜感激。
请您参考如下方法:
如果你想得到名字或工艺品,就这样做:
print("Fist name: ",data["people"][0]["name"])
print("Fist craft: ",data["people"][0]["craft"])
最终你可以像这样把它放在一个for循环中:
for i in range(len(data["people"])):
print(data["people"][i]["name"])
