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)))
3 Answers 3
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
Comments
It's quite simple, really.
You can simply use jQuery's $.parseJSON (jsonString).
Comments
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);
Comments
Explore related questions
See similar questions with these tags.
Objectin the console to see what it contains. Or do aconsole.log(JSON.stringify(parsedData))console.dir()instead.0property you will see an object, if you expand that one'sdatagroupsproperty you will get the inner arrayà