Python Json to array
<p>I want to put json into array.
I have 6 Json links (with the same size but different issues)</p>

<p>That was my try:</p>

<pre><code>data=('0','0')
response = urllib.urlopen(URL)
data[0] = json.loads(response.read())
response = urllib.urlopen(URL)
data[1] = json.loads(response.read())
</code></pre>

<p>Do I have to initialize a 3d array?
Later it would be fine if I can work on the result like that:</p>

<pre><code>result = data[0]['resu']['spc']
</code></pre>

<p>In the end i want to build a for loop which use dynamical the json links like that:</p>

<pre><code>for w in range(0,len(URLs)):
    URLs[w]['resu']['spc']
</code></pre>

<p>I would strongly suggest using <a href="http://docs.python-requests.org/en/master/" rel="nofollow">requests</a> (the current documentation does so, too) but you <em>can</em> do:</p>

<pre><code>import json
import urllib2

urls=["http://example.com/json","https://example.com/json2"] # your urls here

data=[]
for u in urls:
    response = urllib2.urlopen(u)
    data.append(json.loads(response.read())) # while this normally works with Python 2, it is better to use data.append(json.loads(response.read().decode("utf8"))
</code></pre>

<p>for this you have to find out/guess the encoding of your response.</p>

<p>With requests it would be much simpler:</p>

<pre><code>import requests

urls=["http://example.com/json","https://example.com/json2"] # your urls here
data=[requests.get(u).json() for u in urls]
</code></pre>

python arrays json