Extract data from JSON in python
<p>Can I access link inside <code>next</code> from the below <code>Json</code> data? I am doing in this way </p>

<pre><code>data = json.loads(html.decode('utf-8'))
for i in data['comments']:
        for h in i['paging']:
            print(h)
{
</code></pre>

<p>Because <code>comments</code> is a main object. Inside the <code>comments</code> there are three sub objects <code>data</code> , <code>paging</code> and <code>summary</code>. The above code is doing the same , inside <code>comments</code>, because of <code>paging</code> is an object of multiple other objects, in the loop and print that. It is giving the error</p>

<blockquote>
  <p>for h in i['paging']:
  TypeError: string indices must be integers </p>
</blockquote>

<pre><code>    "comments": {
        "data": [
            {
                "created_time": "2016-05-22T14:57:04+0000",
                "from": {
                    "id": "908005352638687",
                    "name": "Marianela Ferrer"
                },
                "id": "101536081674319615443",
                "message": "I love the way you talk! I can not get enough of your voice. I'm going to buy Seveneves! I'm going to read it this week. Thanks again se\u00f1or Gates. I hope you have a beautiful day:-)"
            }
        ],
        "paging": {
            "cursors": {
                "after": "NzQ0",
                "before": "NzQ0"
            },
            "next": "https://graph.facebook.com/v2.7/10153608167431961/comments?access_token=xECxPrxuXbaRqcippFcrwZDZD&amp;summary=true&amp;limit=1&amp;after=NzQ0"
        },
        "summary": {
            "can_comment": true,
            "order": "ranked",
            "total_count": 744
        }
    },
    "id": "10153608167431961"
}
</code></pre>

<p>You're iterating through "comments" which results in three objects: <code>data</code>, <code>paging</code>, and <code>summary</code>. All you want is <code>paging</code>, but your first for-loop wants you to go through all the others.</p>

<p>Thus, when it starts with <code>data</code>, you're trying to call <code>data['paging']</code>, but this doesn't work because <code>data</code>'s value is a list and not a dictionary.</p>

<p>You want to immediately access <code>paging</code>:</p>

<pre><code>print data['comments']['paging']['next']
</code></pre>

python json