How to get array from JSON?
<p>I am trying to fetch data from MySQL table that have 2 columns, Temperature and Value. I want to store these values to JSON and then to pass to the client side script. My PHP code is:
database2json.php:</p>

<pre><code>&lt;?php
    $con = mysql_connect("localhost", "root", "123456");
    if (!$con) {
        die('Could not connect:' . mysql_error());
    }
    mysql_select_db("klima", $con);
    $result = mysql_query("select Dan, Temperatura from TEMPERATURA");
        $niz = array();
    while ($row = mysql_fetch_array($result)) {
        $niz[$row['Dan']] = $row['Temperatura'];
    }
        mysql_close($con);
        $obj = json_encode($niz);
        echo $obj;
?&gt;
</code></pre>

<p>When I run this file on server I get this:</p>

<pre><code>{"1":"-1","2":"0","3":"0","4":"0","5":"4","6":"5","7":"3","8":"2","9":"2","10":"1","11":"-2","12":"-2","13":"0","14":"1","15":"-2","16":"-1","17":"-1","18":"-2","19":"-1","20":"3","21":"-1","22":"0","23":"1","24":"3","25":"1","26":"1","27":"-1","28":"-1","29":"4","30":"5","31":"5"}
</code></pre>

<p>That is what is expected.</p>

<p>Html is nothing special.</p>

<p>index.html:</p>

<pre><code>&lt;html&gt;
    &lt;head&gt;
        &lt;title&gt;jQuery&lt;/title&gt;
        &lt;script src="jquery.js" type="text/javascript"&gt;&lt;/script&gt;
        &lt;script src="custom.js" type="text/javascript"&gt;&lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;div id="id1"&gt;&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>

<p>Now I call php from jQuery and to show these values.</p>

<p>custom.js:</p>

<pre><code>$(document).ready(function(){
    $.post('database2json.php', function(data){
        $('#id1').html(data);
    },
    "json");
});
</code></pre>

<p>This also gives same output like php:</p>

<blockquote>
  <p>{"1":"-1","2":"0","3":"0","4":"0","5":"4","6":"5","7":"3","8":"2","9":"2","10":"1","11":"-2","12":"-2","13":"0","14":"1","15":"-2","16":"-1","17":"-1","18":"-2","19":"-1","20":"3","21":"-1","22":"0","23":"1","24":"3","25":"1","26":"1","27":"-1","28":"-1","29":"4","30":"5","31":"5"}</p>
</blockquote>

<p>Now I dont know how to convert this into array of [Dan, Temperatura]. I need this array to forward to chart and plot data (I am not asking about plotting, just to get array).</p>

<p>How to achieve this?</p>
