Problem mit Dictionary
Verfasst: Sonntag 26. Januar 2020, 10:58
Hallo,
bin neu hier im Forum und auch neu in Python bzw. Micropython auf ESP32.
Ich hab ein Json-String als Dictionary vorliegen.
[======= JSON-String als Dictionary ========
{'timezone': 3600, 'cod': 200, 'dt': 1580024773, 'base': 'stations', 'weather': [{'id': 741, 'icon': '50d', 'main': 'Fog', 'description': 'Nebel'}], 'sys': {'country': 'AT', 'sunrise': 1580020060, 'sunset': 1580053611, 'id': 6871, 'type': 1}, 'name': 'xxxxxxx', 'clouds': {'all': 90}, 'coord': {'lon': 16.25, 'lat': 46.99}, 'visibility': 500, 'wind': {'speed': 1}, 'id': 7871565, 'main': {'feels_like': -6.85, 'pressure': 1022, 'temp_min': -4.44, 'humidity': 92, 'temp_max': -2.78, 'temp': -3.57}}
*]
Ich kann auf zB 'main' folgenderweise zugrefen >> wetterdaten_main = wetterdaten["main"]
Mein Problem ist: Ich möchte auf 'weather' zugreifen und daraus 'description' auslesen.
Hab schon einiges probiert, aber ich bekomme immer folgende Fehlermeldung:
TypeError: list indices must be integers, not str
Vielleicht kann mir wer einen Tipp geben.
MfG
Gerhard
bin neu hier im Forum und auch neu in Python bzw. Micropython auf ESP32.
Ich hab ein Json-String als Dictionary vorliegen.
[======= JSON-String als Dictionary ========
{'timezone': 3600, 'cod': 200, 'dt': 1580024773, 'base': 'stations', 'weather': [{'id': 741, 'icon': '50d', 'main': 'Fog', 'description': 'Nebel'}], 'sys': {'country': 'AT', 'sunrise': 1580020060, 'sunset': 1580053611, 'id': 6871, 'type': 1}, 'name': 'xxxxxxx', 'clouds': {'all': 90}, 'coord': {'lon': 16.25, 'lat': 46.99}, 'visibility': 500, 'wind': {'speed': 1}, 'id': 7871565, 'main': {'feels_like': -6.85, 'pressure': 1022, 'temp_min': -4.44, 'humidity': 92, 'temp_max': -2.78, 'temp': -3.57}}
*]
Ich kann auf zB 'main' folgenderweise zugrefen >> wetterdaten_main = wetterdaten["main"]
Mein Problem ist: Ich möchte auf 'weather' zugreifen und daraus 'description' auslesen.
Hab schon einiges probiert, aber ich bekomme immer folgende Fehlermeldung:
TypeError: list indices must be integers, not str
Vielleicht kann mir wer einen Tipp geben.
MfG
Gerhard