0

我尝试合并类似的东西(我在 json 中显示)

[["Field1","0"],["Field2","0"],["Field3","0"]]

{"0":{"Name":"Foo","Lastname":"Bar"}} 

当我做

$.extend({}, firstArray, secondArray);

我进入 JSON

{
 "0":{"Name":"Foo","Lastname":"Bar"},
 "1":["Field1","0"],
 "2":["Field2","0"]
} 

如您所见,第一个数组与第二个数组混合在一起。我希望它像这样被包裹起来

{
"0":{"Name":"Foo","Lastname":"Bar"},
"1":[ "1": ["Field1","0"],"2":["Field2","0"]]
} 

因此,稍后当我使用它时,我可以将字段内容作为一个数组获取。有可能吗?我无法让它工作。有任何想法吗?

4

2 回答 2

1

看起来您只需要添加secondArray为 的属性firstArray,而是转换为对象。可以这样完成:

firstArray["1"] = $.extend({}, {}, secondArray);

现在firstArray变成:

{
"0":{"Name":"Foo","Lastname":"Bar"},
"1":{"0": ["Field1","0"], "1":["Field2","0"]}
} 

我希望这已经足够好了。

于 2013-01-11T23:03:15.927 回答
0

firstarray = firstarray.concat(secondarray)

于 2013-01-11T23:02:05.247 回答