0

I have the following JSON object :

var myObject = {"priorityset": 
  [
    {"name":"Prio1", "valueA":"0", "valueB":"0", "valueC":"0", "valueD":"1"}, 
    {"name":"Prio2", "valueA":"1", "valueB":"0", "valueC":"0", "valueD":"1"}, 
    {"name":"Prio3", "valueA":"0", "valueB":"0", "valueC":"0", "valueD":"1"}
  ]
};

I want to modify this object so I get something like this:

var myObject = 
[
  {"name":"Prio1", "valueA":"0", "valueB":"0", "valueC":"0", "valueD":"1"}, 
  {"name":"Prio2", "valueA":"1", "valueB":"0", "valueC":"0", "valueD":"1"}, 
  {"name":"Prio3", "valueA":"0", "valueB":"0", "valueC":"0", "valueD":"1"}
];

I have tried to solve this by myself, but no solution so far. Any ideas?

Thanks in advance.

4

1 回答 1

3

First, json is a string-based data format. You have an object literal with a property, the value of which is an array that contains object literals. From what I see, you just want the property.

myObject = myObject.priorityset;

Equally valid is

myObject = myObject['priorityset'];

which is another way to do property access on an object literal.

于 2012-04-26T12:26:23.037 回答