Variable in JSON path
<p>I would like to make the path to data contained in JSON variable.
The code I have now looks like this:</p>

<pre><code>function writeDB(block)
{
  $.getJSON('js/data.js', function(data) {

    if (block == "path1") { var adr = data.test.path1.db; };
    if (block == "path2") { var adr = data.test.path2.db; };
    if (block == "path3") { var adr = data.test.path3.db; };

    var datastring="";
    $.each(adr, function(i, field){
      temp = encodeURIComponent($("#writeDB_"+block+" [name="+adr[i].abc+"]").val());
      datastring += adr[i].abc+"="+temp+"&amp;";
    });

  });

}
</code></pre>

<p>The "if" parts I would like to simplify and make it variable, by using the variable 'block' directly into the "adr" path, something like this</p>

<pre><code>var adr = "data.test."+block+".db";
</code></pre>

<p>But a string won't work, so its useless. Someone knows how I can fix that?</p>
