になるこのJSONを再構築します:どのように私はそうのようにフォーマットされたいくつかのJSONデータを持っているよりアクセス
[ {"stage1" : [{
"checkpoints" :
[
{
"id" : "checkpoint1",
"name" : "a checkpoint name 1",
"purpose" : "a string about the purpose here",
},
{
"id" : "checkpoint2",
"name" : "a checkpoint name 2",
"purpose" : "a string about the purpose here",
}
],
"stages" :
[
{
"id" : "an id here",
"name" : "a checkpoint name 1",
"purpose" : "a string about the purpose here yah",
}
]
}
]},
{"stage2" : [{
"checkpoints" :
[
{
"id" : "checkpoint1",
"name" : "a checkpoint name 1",
"purpose" : "a string about the purpose here",
},
{
"id" : "checkpoint2",
"name" : "a checkpoint name 2",
"purpose" : "a string about the purpose here",
}
],
"stages" :
[
{
"id" : "an id here",
"name" : "a checkpoint name 1",
"purpose" : "a string about the purpose here yah",
}
]
}
]},
{"stage3" : [{
"checkpoints" :
[
{
"id" : "checkpoint1",
"name" : "a checkpoint name 1",
"purpose" : "a string about the purpose here",
},
{
"id" : "checkpoint2",
"name" : "a checkpoint name 2",
"purpose" : "a string about the purpose here",
}
],
"stages" :
[
{
"id" : "an id here",
"name" : "a checkpoint name 1",
"purpose" : "a string about the purpose here yah",
}
]
}
]},
]
現在、私は段階で取得するには、このようなデータを参照する必要があります。
alert(data[0].stage1[0].checkpoints.length);
は、ステージ2データを取得するために私はこれをしなければならない:私はちょうど、ACCに芸名を使用している行うことができるようにしたいどのような
alert(data[1].stage2[0].checkpoints.length);
「データ」の宣言後にインデックスを指定することなく、ESSデータ:
alert(data.stagex[0].checkpoints.length);
私はデータ部分の後にインデックスを述べるために持っている必要はありません。 JSONを再構築するにはどうすればいいですか?最初にインデックスを指定せずに必要なデータを取得するためにステージ名を使用できますか?
オブジェクトの配列は、それぞれプロパティ( 'stageX')が1つだけです。このプロパティを持つことはまったく必要ではないようですが、私はそれを削除するだけです。あるいは配列を持たずに、プロパティとして 'stage1'、' stage2'を持つ* one *オブジェクトを作成してください。 –
また、チェックポイントの長さ属性はどのようにステージを参照していますか? – Amberlamps