如何将多维JSON对象转换为javascript数组 [英] How do I convert a multi dimensional JSON object into javascript array

查看:112
本文介绍了如何将多维JSON对象转换为javascript数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像这样的JSON对象:

I have a JSON object which looks like this:

[{"tabname":"orders","datagroups":[{"dataname":"ordersToday","datavalue":9},{"dataname":"orders30Days","datavalue":126}]}] 

当我使用console.log($.parseJSON(thedata)) 我只得到单词Object而没有实际数据.

When I use console.log($.parseJSON(thedata)) I just get the word Object and no actual data.

如何将这些数据组织到多维javascript数组中?这样看起来像这样:

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)))  

推荐答案

感谢大家的贡献.我休息了一会儿,然后回来想通了.我的大脑运作方式全错了.

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);

这篇关于如何将多维JSON对象转换为javascript数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆