gdogg371
gdogg371

Reputation: 4122

'string indices must be integers' error with this JSON dict

I have a dictionary with a single item in it created using json.loads(). The data structure looks like this:

{"teamId":96}

When I attempt to access the dictionary value by using the following:

mydict = mydict[u'teamId']

I get the following error:

Traceback (most recent call last):
  File "C:\Python27\counter.py", line 65, in <module>
    print home_team[u'teamId']
TypeError: string indices must be integers

Can anyone explain to me what the issue is here? The code looks like it should work to me.

Thanks

Upvotes: 0

Views: 806

Answers (1)

Kasravnd
Kasravnd

Reputation: 107287

You need json.dumps(you_file) :

json.loads(json.dumps(your_file))

Upvotes: 1

Related Questions