title: TypeError: string indices must be integers error when parsing Json with Python
body: <p>Before you judge and think to yourself 'I've seen this question a thousand times' please read on and give me a chance, I've scoured the internet for answers but can't seem to find any help.</p>
  
  <p>So I am trying to parse json from an API which I obtain using the following code:</p>
  
  <pre><code>url = 'https://api.companieshouse.gov.uk/company/' + companyno + '/charges'
  
  r = requests.get(url, auth=('API KEY', ''))
  
  data = r.json()
  </code></pre>
  
  <p>I can get specific values from the json pretty easily, for example using this code:</p>
  
  <pre><code>for each in data['items']:
      print(each['created_on'])
  </code></pre>
  
  <p>which returns:</p>
  
  <pre><code>2016-11-08
  2016-11-08
  2016-11-08
  2015-03-27
  2015-03-27
  2015-03-27
  2015-03-27
  2015-03-27
  2007-10-10
  2007-09-28
  2007-09-19
  </code></pre>
  
  <p>And this is exactly what I want, it works for other keys to.</p>
  
  <p>However there is one bit of the json which I just can't seem to access, I have slightly edited the json as to avoid releasing sensitive data (which is available to the public anyway but just to be cautious) but it is largely unchanged:</p>
  
  <pre><code>{  
     'items':[  
        {  
           'created_on':'2016-11-08',
           'etag':'DELETED',
           'classification':{  
              'type':'charge-description',
              'description':'A registered charge'
           },
           'particulars':{  
              'contains_negative_pledge':True,
              'description':'DELETED',
              'type':'brief-description'
           },
           'transactions':[  
              {  
                 'links':{  
                    'filing':'DELETED'
                 },
                 'filing_type':'create-charge-with-deed',
                 'delivered_on':'2016-11-21'
              }
           ],
           'links':{  
              'self':'DELETED'
           },
           'charge_code':'DELETED',
           'delivered_on':'2016-11-21',
           'status':'outstanding',
           'persons_entitled':[  
              {  
                 'name':'DELETED'
              },
              {  
                 'name':'DELETED'
              }
           ],
           'charge_number':59
        },
        {  
           'transactions':[  
              {  
                 'delivered_on':'2016-11-10',
                 'links':{  
                    'filing':'DELETED'
                 },
                 'filing_type':'create-charge-with-deed'
              }
           ],
           'particulars':{  
              'contains_negative_pledge':True,
              'contains_fixed_charge':True,
              'floating_charge_covers_all':True,
              'contains_floating_charge':True
           },
           'persons_entitled':[  
              {  
                 'name':'DELETED'
              }
           ],
           'charge_number':58,
           'status':'outstanding',
           'charge_code':'DELETED',
           'links':{  
              'self':'DELETED'
           },
  </code></pre>
  
  <p>It is the [items, links, self] data </p>
  
  <p>If I use the following code to try and access it:</p>
  
  <pre><code>for each in data['items']['links']:
      print(each['self'])  
  </code></pre>
  
  <p>I get the following error:</p>
  
  <pre><code>  File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  TypeError: list indices must be integers or slices, not str
  </code></pre>
  
  <p>And if I try to access it using the following code:</p>
  
  <pre><code>for each in data['items'][0]['links']:
          print(each['self'])
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>  File "&lt;stdin&gt;", line 2, in &lt;module&gt;
  TypeError: string indices must be integers
  </code></pre>
  
  <p>I just cant understand why its throwing this error at me, all the other responses on the internet point towards the fact that I am trying to parse a string and not an actual json object but whenever I run the command:</p>
  
  <pre><code>type(data)
  </code></pre>
  
  <p>it returns:</p>
  
  <pre><code>&lt;class 'dict'&gt;
  </code></pre>
  
  <p>So I know it is a dictionary and that it should be able to iterate through the keys.</p>
  
  <p>I'm sure I'm making a very stupid mistake and if so I apologize but I just can't figure out what I'm doing wrong, can anyone help?</p>
  
  <p>p.s. sorry for the long post.</p>
  
  <p>EDIT:</p>
  
  <p>Thanks so much for all your replies, things seems to make sense now. We were all learners at one point! :)</p>