使用自定义格式将String Array转换为JSON Array

时间:2018-01-03 13:49:15

标签: jquery json

我想问一个关于将数组转换为jsonArray的问题。这是我获取jsonArray的代码

[
  {id=10,job:computer, place:near}
  {id=11,job:computer2, place:near2}
  [   
    {id=14,job:computer, place:near3}  
    {id=11,job:computer2, place:near2}
    {id=10,job:computer2, place:near2}
  ],
  {id3=101,jobr:computerr, placer:nearr} 
  [   
    {id3=14,jobr:computerr, placre:nearrrr}             
  ],
]

我需要这种格式的json。但是

var arr = 
[
  {
    id:'grid1',
    all:
    [    
      {id=14,job:computer, place:near3},   
      {id=11,job:computer2, place:near2},            
      {id=10,job:computer2, place:near2}
    ],
    change:
    [   
      {id=10,job:computer, place:near}
      {id=11,job:computer2, place:near2}
    ]   
  },
  {
    id:'grid2',
    all:
    [    
      {id3=14,jobr:computerr, placre:nearrrr}  
    ],
    change:
    [   
      {id3=101,jobr:computerr, placer:nearr}
    ]
  }
]

我的代码使用

obj = {};

$.each(cols[0].Values,function(key,value){
   obj[value.Value] = value.Display;
});

1 个答案:

答案 0 :(得分:0)

以下是我解决这个问题的方法:

var coords=[]
  coords.push({ 'Id': $(myGrid)[0].id, 'ChangeRecord': coords2, 'all': gridData });
相关问题