ich hab ein Problem und leider noch nirgends eine Lösung gefunden. Vielleicht habe ich auch nicht "richtig" gesucht aber ich weiß nicht was der Fehler ist und tu mir so mit dem Suchen schwer.
Ich habe einen Raspberry Pi mit Raspbian und python.
Ich möchte Feiertage die ich per JSON über eine API beziehe ausgeben und weiterverarbeiten.
Code: Alles auswählen
import urllib.request, json
with urllib.request.urlopen("https://xxxxxxx.xx/api/Data/GeoId/?api_key=xxxxxxxxxxxx") as url:
data = json.loads(url.read().decode())
for event in data:
print(event['description'])
Eigentlich sollte print die liste Feiertage ausgeben, leider kommt aber folgende Fehlermeldung:
Traceback (most recent call last):
File "getjson.py", line 6, in <module>
print(event['description'])
TypeError: string indices must be integers
Ich hab schon viel herumprobiert was man so in anderen Foren oder Seiten findet - bin aber nicht draufgekommen.
Bitte um Hilfe - Danke Martin
PS: Hier die JSON Daten:
Code: Alles auswählen
{
"interface":"XXXX",
"source":{"href":"https:\/\/XXXX.xx",
"description":"xxxx.xx"},
"copyright":{"href":"https:\/\/xxx.xx","description":"xxxxxxxxxx"},
"apiName":"Data\/GeoId",
"apiStatus":{"description":"active"},
"date":"02.03.19",
"request":{"geoId":"3126","year":"2019","class":"4","charset":"utf-8","format":"json","date_format":"d.m.y","hl":"de"},
"results":{"status":{"description":"ok"},
"location":{"description":"Nieder\u00f6sterreich",
"type":"Bundesland",
"geoId":"3126",
"iso":"AT",
"iso-3166-2":"AT-3",
"events":[
{"description":"Neujahr", "id":"1","dateStart":"01.01.19","dateEnd":"01.01.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Heilige drei K\u00f6nige", "id":"4","dateStart":"06.01.19","dateEnd":"06.01.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Ostern", "id":"18","dateStart":"21.04.19","dateEnd":"21.04.19","class":"4","percent":"100","prov":"0","note":null},
{"description":"Ostermontag", "id":"19","dateStart":"22.04.19","dateEnd":"22.04.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Staatsfeiertag \u00d6sterreich", "id":"75","dateStart":"01.05.19","dateEnd":"01.05.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Christi Himmelfahrt", "id":"31","dateStart":"30.05.19","dateEnd":"30.05.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Pfingsten", "id":"30","dateStart":"09.06.19","dateEnd":"09.06.19","class":"4","percent":"100","prov":"0","note":null},
{"description":"Pfingstmontag", "id":"35","dateStart":"10.06.19","dateEnd":"10.06.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Fronleichnam", "id":"38","dateStart":"20.06.19","dateEnd":"20.06.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Mari\u00e4 Himmelfahrt", "id":"42","dateStart":"15.08.19","dateEnd":"15.08.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Nationalfeiertag \u00d6sterreich", "id":"74","dateStart":"26.10.19","dateEnd":"26.10.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Allerheiligen", "id":"47","dateStart":"01.11.19","dateEnd":"01.11.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Allerseelen", "id":"99","dateStart":"02.11.19","dateEnd":"02.11.19","class":"4","percent":"100","prov":"0","note":null},
{"description":"St. Leopold", "id":"103","dateStart":"15.11.19","dateEnd":"15.11.19","class":"4","percent":"100","prov":"0","note":null},
{"description":"Mari\u00e4 Empf\u00e4ngnis", "id":"51","dateStart":"08.12.19","dateEnd":"08.12.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Christtag", "id":"23","dateStart":"25.12.19","dateEnd":"25.12.19","class":"1","percent":"100","prov":"0","note":null},
{"description":"Stefanitag", "id":"37","dateStart":"26.12.19","dateEnd":"26.12.19","class":"1","percent":"100","prov":"0","note":null}
]}}}