It sounds a lot more complicated than it really is.
So in Perl, you can do something like this:
foreach my $var (@vars) { $hash_table{$var->{'id'}} = $var->{'data'}; }
I have a JSON object and I want to do the same thing, but with a javascript associative array in jQuery.
I’ve tried the following:
hash_table = new Array(); $.each(data.results), function(name, result) { hash_table[result.(name).extra_info.a] = result.(name).some_dataset; });
Where data is a JSON object gotten from a $.getJSON call. It looks more or less like this (my JSON syntax may be a little off, sorry):
{ results:{ datasets_a:{ dataset_one:{ data:{ //stuff } extra_info:{ //stuff } } dataset_two:{ ... } ... } datasets_b:{ ... } } }
But every time I do this, firebug throws the following error:
‘XML filter is applied to non-xml data’
I think you can use the JSON response as an associative array. So you should be able to go directly in and use the JSON.
Assuming you received the above example:
Understand that I haven’t tested this, but it’s safer to use the square brackets with a variable than it is to use parenthesis plus the name with the dot accessor.
Your example is failing because of some convoluted logic I just caught.
Now, the foreach loop goes through the variable
data.resultsto find the internal elements at a depth of 1. The item it finds is given to the lambda with the key of the item. AKA, the first result will bename = 'datasets_a' item = object. Following me so far? Now you access the returned hash, the object initem, as though it has the child key inname… ‘datasets_a’. But wait, this is the object!If all else fails… write your result JSON into a text field dynamically and ensure it is formatted properly.