I'm trying to get forecast information, but I just started with JSON, so I'm having a hard time with the basics.
How do I get info for period 0?
fc = parsed_json['forecast']['txt_forecast']['period']['icon']
How do I get info for period 0?
fc = parsed_json['forecast']['txt_forecast']['period']['icon']
- 3 Posts
- 0 Reply Likes
Posted 7 years ago
- 3 Posts
- 0 Reply Likes
for i in range (0,7):
fc[i]
print fc[0]
--------
so, this prints
{u'title': u'Saturday', u'icon_url': u'http://icons-ak.wxug.com/i/c/k/mostly...', u'fcttext_metric': u'Mostly cloudy in the morning, then overcast. Fog early. High of 15C. Winds from the NNE at 5 to 15 km/h.', u'period': 0, u'pop': u'0', u'fcttext': u'Mostly cloudy in the morning, then overcast. Fog early. High of 59F. Winds from the NNE at 5 to 10 mph.', u'icon': u'mostlycloudy'}
How can I fetch the value for 'icon'?
fc[i]
print fc[0]
--------
so, this prints
{u'title': u'Saturday', u'icon_url': u'http://icons-ak.wxug.com/i/c/k/mostly...', u'fcttext_metric': u'Mostly cloudy in the morning, then overcast. Fog early. High of 15C. Winds from the NNE at 5 to 15 km/h.', u'period': 0, u'pop': u'0', u'fcttext': u'Mostly cloudy in the morning, then overcast. Fog early. High of 59F. Winds from the NNE at 5 to 10 mph.', u'icon': u'mostlycloudy'}
How can I fetch the value for 'icon'?
- 227 Posts
- 43 Reply Likes
I was not able to understand the language you're using but I suppose it's python: if so, it seems you can access the data as a dictionary.
- 3 Posts
- 0 Reply Likes
Yes, it's Python. Can you be more specific? Remember it's the first time I'm doing something like this. I'm even new to Python.
What do you mean with "access data as a dictionary? How can I find the available "dictionary items"?
Thanks
--------
Edit: Googling "python dictionaries" shows a lot of interesting stuff. I think I have enough to continue. Thank you!
What do you mean with "access data as a dictionary? How can I find the available "dictionary items"?
Thanks
--------
Edit: Googling "python dictionaries" shows a lot of interesting stuff. I think I have enough to continue. Thank you!
- 227 Posts
- 43 Reply Likes
You're welcome, anyway the reference I spotted about python dictionaries was at http://docs.python.org/2/tutorial/dat...