1

I get a JSON data with this format:

{
 key1: val1,
 key2: val2,
 key3: val3,
 key4: val4,
 ..
}

Now I want to change it to another format in Javascript:

[
    {key: "key1", value: value1},
    {key: "key2", value: value2},
    {key: "key3", value: value3},
    {key: "key4", value: value4},   
    ...     
]

Is there some libraries that can do this? Or I have to write a function?

Please give me some tips! Thanx!

4

1 回答 1

7
var newObject = Object.keys(originalObject).map(function(k) { 
  return { key: k, value: originalObject[k] };
});
于 2013-11-11T14:43:46.710 回答