Reputation: 1489
I have a JSON object which looks like this:
[{"tabname":"orders","datagroups":[{"dataname":"ordersToday","datavalue":9},{"dataname":"orders30Days","datavalue":126}]}]
When I use console.log($.parseJSON(thedata))
I just get the word Object
and no actual data.
How do I organise this data into a multidimensional javascript array? so that it looks something like this:
array("tabname"=>"orders", "datagroup"=>array(array("dataname"=>"ordersToday", "datavalue"=>9),array("dataname"=>"orders30Days","datavalue"=>126)))
Upvotes: 1
Views: 4619
Reputation: 1489
Thanks to everyone for contributing. I took a break then came back and figured it out. The way my brain works is all wrong.
To access the individual values, I needed to do something like this:
var orderStats = $.parseJSON(data);
console.log(orderStats[0].datagroups[0].dataname);
Upvotes: 0
Reputation: 5243
It's quite simple, really.
You can simply use jQuery's $.parseJSON (jsonString)
.
Upvotes: 0
Reputation: 185883
It is an array:
var json = '[{"tabname":"orders","datagroups":[{"dataname":"ordersToday","datavalue":9},{"dataname":"orders30Days","datavalue":126}]}]';
var obj = $.parseJSON(json);
Array.isArray(obj) // => true
Upvotes: 1