私は次のオブジェクトを持っています
{
"locations": {
"Base 1": {
"title": "This is base 1",
"Suburb 1": {
"title": "Suburb 1 in Base 1",
"Area A": {
"title": "Title for Area A",
"Street S1": {
"title": "Street S1 title"
},
"Street C4": {
"title": "Street C4 title"
},
"Street B7": {
"title": "Street B7 title"
}
},
"Another Area": {
"title": "Title for Area A",
"Street S1": {
"title": "Street S1 title"
},
"Street C4": {
"title": "Street C4 title"
},
"Street B7": {
"title": "Street B7 title"
}
}
},
"Another Suburb": {
"title": "Suburb 1 in Base 1",
"Area A": {
"title": "Title for Area A",
"Street S1": {
"title": "Street S1 title"
},
"Street C4": {
"title": "Street C4 title"
},
"Street B7": {
"title": "Street B7 title"
}
},
"Another Area": {
"title": "Title for Area A",
"Street S1": {
"title": "Street S1 title"
},
"Street C4": {
"title": "Street C4 title"
},
"Street B7": {
"title": "Street B7 title"
}
}
}
},
"Base2": {}
}
}
「場所」オブジェクトから「タイトル」を取得するための配列が与えられ、各配列は異なる場合があります。私は次のように個々の値にアクセスできることを知っています:
locations["Base 1"]["title"]
locations["Base 1"]["Another Suburb"]["title"]
locations["Base 1"]["Another Suburb"]["Area A"]["title"]
etc etc.
しかし、次のような配列が与えられた場合、タイトルの値を取得する方法がわかりません:
AnArray = ["Base 1", "title"];
AnArray = ["Base 1", "Another Suburb", "title"];
AnArray = ["Base 1", "Another Suburb", "Area A", "title"];
AnArray = ["Base 1", "Another Suburb", "Another Area", "title"];
これらの配列を解析/操作して、それぞれが場所オブジェクトから正しいタイトル値を返す方法はありますか?
それぞれの場合にタイトルの値を取得する必要があり、どこから始めればよいかさえわかりません。配列に参加してから、「タイトル」の値をフェッチしようとしましたが、うまくいかないようでした。
ここでは初心者なので、質問がばかげているように聞こえたり、意味がなかったりしても気にしないでください。
問題は、参照が配列にある場合に階層オブジェクトから値を取得するにはどうすればよいかということです。