0

这是我的 json 有效负载

"multiList": [
  {
    "Key": "my_key",
    "Value": this is my key
  },
  {
    "Key": "my_text_box",
    "Value": "This is my text box"
  },

]

如何使用 jquery 动态转换它

"multiList": [
  {
    "my_key" : "this is my key"
  },
  {
    "my_text_box": "This is my text box"
  },

]

4

1 回答 1

0

例如 :

yourobj.multiList = yourobj.multiList.map(function(v) {
   var r = {};
   r[v.Key] = v.Value;
   return r;
});

如果你想支持 IE8,你必须使用 shim 来映射或使用for而不是map

for (var i=0; i<yourobj.multiList.length; i++) {
    var v = yourobj.multiList[i];
    var r = {};
    r[v.Key] = v.Value;
    yourobj.multiList[i] = r;
}
于 2013-04-05T19:21:52.447 回答