Json对象拆分为json字符串 [英] Json Object split into json string

查看:120
本文介绍了Json对象拆分为json字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下数据是我的json对象

The below data is my json object

var column = {
    "SNo": [{ "group": "true", "sort": "true", "filter": "true", "type": "number", "min": 1, "max": 1000, "format": "{0:c}"}],
    "Name": [{ "group": "true", "sort": "true", "type": "string", "columnmenu": "true"}],
    "City": [{ "group": "true", "type": "number", "filter": "true", "width": "100px", "columnmenu": "false"}]
};

我需要将上述数据拆分成数组列表而不循环

I need the above data split into array list without looping

第一个数组列表: [SNo,Name,City]

第二个数组列表: [group,sort,filter,type,min,max,format,group,sort,type ,columnmenu,group,type,filter,width,columnmenu]

第三个数组列表: [true,true,true,number,1,1000,{0:c},true,true,string,true ,true,number,true,100px,false]

第四个数组列表: [7,4,5] //每个属性的数量

Fourth array list : [7, 4, 5] // count of each attributes

请帮助我。我是这个领域的新手。否则减少最大no.of循环。

Please help me. am new of this field. otherwise reduce the maximum no.of loops.

推荐答案

这里我还有一些工作,当你可以在列对象中有更多的键。

Here I also got something working when you can have more keys in columns object.

var first_array = Object.keys(column);
var second_array = []; 
var third_array = []; 
var fourth_array = [];

first_array.forEach(function(inner_key){
    var keysInInnerKey = Object.keys(column[inner_key][0]);
    var valuesInInnerKey = keysInInnerKey.map(function(key){
        return column[inner_key][0][key];
    });
second_array = second_array.concat(keysInInnerKey);
third_array = third_array.concat(valuesInInnerKey);
fourth_array.push(keysInInnerKey.length);
});

这篇关于Json对象拆分为json字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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