这与主题无关,但如果您只想将设置值和punchline值写入文本文件,可以执行以下操作:
# Dependencies
import json
import requests
# Specify the URL
url = "https://official-joke-api.appspot.com/jokes/programming/ten"
# Make request and store response
r = requests.get(url)
print("Status code:", r.status_code)
jokes = json.loads(r.text)
with open("outfile.txt", "w") as f:
for joke in jokes:
f.write("{}:{}\\n".format(joke["setup"], joke["punchline"]))