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>Tuples are immutable which makes them great for sharing between threads, but not so good for frequent changes.  Try using a list instead as they are designed for this very use case.  That being said, a dictionary can be nice as well:</p>

<pre><code>import json
import urllib.request

data = {}
for url in urls:
    with urllib.request.urlopen(url) as response:
        if response.status_code != 200: 
            continue // Handle errors here, I chose to continue
        // Remember that JSON must be in text format
        data[url] = json.loads(response.read().decode())
</code></pre>

<p>Just for giggles, here is a one liner:</p>

<pre><code>// The lack of error checking in this is staggering though!
data = {u:json.loads(urllib.request.urlopen(u).read().decode()) for u in urls}
</code></pre>

python arrays json