0

データベースからデータを読み取っています: 必要な値があります

    for (var index in entities) {                                                                  
    console.log(entities[index].PartitionKey);                                                                    
    console.log(entities[index].RowKey);                                                                       
    console.log(entities[index].Details);                                                               
    console.log(entities[index].Date);
    }

上記は、必要なすべてのデータを出力します。これをJsonオブジェクトとして変換したいと思います。どうやってやるの 。

私はJSON.stringifyを使用できることを使用して認識していますが、このコンテキストでこれを試していると、エラーが発生します。

私はforloopにとどまろうとしました:

jasonarray[index1].PartitionKey     = entities[index].PartitionKey;
jasonarray[index1].RowKey           = entities[index].RowKey;

JSON.stringify({ key: jasonarray[index1].PartitionKey, RowKey: jasonarray[index1].RowKey )

しかし、この関数の実行に関しては未定義として与えています。

私が探しているのは var x だけです:

where x is a 

[

{partionkey: "val",key: "val"}
{partionkey: "val",key1: "val"}
{partionkey: "val",key2: "val"}

]
4

1 に答える 1

2

Javascript: 作業サンプルhttp://fiddle.jshell.net/xrB8J/

var entities = [
    {PartitionKey: 'a', RowKey: 5, Details:'details 1', Date:'01.01.2012' },
    {PartitionKey: 'b', RowKey: 7, Details:'details 2', Date:'02.01.2012' },
    {PartitionKey: 'c', RowKey: 3, Details:'details 3', Date:'03.01.2012' }
];

var a = new Array();
for(i = 0; i < 3; i++) 
    a.push({
        PartitionKey: entities[i].PartitionKey, 
        RowKey: entities[i].RowKey
    });

alert(JSON.stringify(a));

または c#:

string json = (new JavascriptSerializer()).Serialize(entities.Select(x => new
    {
        x.PartitionKey,
        x.RowKey
    }
));
于 2012-11-24T20:58:10.637 に答える