I'm only a few days into my Python experience so I'm sorry to pollute the site with a baby-steps question. I'm trying to write an add-on for XBMC, which I believe uses Python 2.4. I've accessed a web api, which wraps the return in JSON. I've saved the url return to a WebHTML list (I think a list!). When I enter the following from the stackoverflow tutorial:
decoded = json.loads(WebHTML)
print 'DECODED:', decoded
I get the following in my log:
NOTICE: {u'totalItems': 1, u'query': u'Ludwig van Beethoven Op 67 Symphony No 5 in Cm (Fate)', u'kind': u'volumes#volumes', u'items': [{u'scoreId': u'IMSLP01056', u'pageCount': 42, u'title': u'Symphony No.5, Op.67 - Complete Score (S.464/5)', u'kind': u'volumes#volume', u'authors': [u'Beethoven, Ludwig van'], u'year': 1807, u'selfLink': u'http://www.peachnote.com/rest/api/v0/score?id=IMSLP01056'}]}
I want to extract the scoreId for a subsequent url call, i.e. IMSLP01056, but I'm struggling with the correct command. When I try:
dict = json.loads(WebHTML)
dict['items']['scoreId']
print dict['items']['scoreId']
The log error returned is:
TypeError: list indices must be integers, not str
If I try:
print dict[4][1]
it returns
KeyError: (4,)
I've tried a variety of JSONloads commands but can't get any to work. I always get an error beginning:
IOError: (2, 'No such file or directory', '{\n "kind": "volumes#volumes",\n "query": "Ludwig ..... etc, etc.
So, I'm a little stumped as to the correct command I should use. Thanks and sorry if this is too much info for a very basic question.
dictas a variable name is a very bad idea as it shadows the built-in name.