#pm2.5 讀取與寫入 # -*- coding: utf-8 -*- """ Created on Tue Dec 17 22:34:02 2019 @author: User """ import requests r = requests.get("https://opendata.epa.gov.tw/ws/Data/AQI/?$format=json", verify=False) list_of_dicts = r.json() print(type(r)) print(type(list_of_dicts)) for i in list_of_dicts: print(i["County"], i["SiteName"], i["PM2.5"]) with open("data_pm25.txt", "w", encoding="utf-8") as file: for i in list_of_dicts: file.write(i["County"] + " " + i["SiteName"] + " " + i["PM2.5"]+"\n")