/ /配列のサブサブディレクトリ内を検索して親辞書を返す(Objective C) - objective-c、ios、nsmutablearray

親辞書を返すために配列のサブサブディクリー内を検索する(Objective C) - objective-c、ios、nsmutablearray

私は以下のような構造化された配列を持っています

 (
{
id = 0;
name = "A";
tables =         (
{
comment = "";
id = 0;
name = "T1";
},
{
comment = "";
id = 1;
name = "T2";
},
{
comment = "";
id = 4;
name = "T3";
}
);
},
{
id = 1;
name = "B";
tables =         (
{
comment = "";
id = 5;
name = "T1";
},
{
comment = "";
id = 6;
name = "T2";
}
);
}
)

辞書のidキーの値を知っているとすれば、どのようにして親辞書を得るか、より正確には名前キー(この場合はB)の値を得ることができます。

私は述語文字列を使用しようとしましたが、問題は親辞書にもidという名前のキーがあるため、間違った結果が得られることです。

EDIT:idキーはユニークです(また、最初のディクショナリの要素のIDが高いインデックスを持つディクショナリのIDよりも低いintiger値を持つ必要はありません)

回答:

回答№1は0

これを試してください。 アレイ あなたの構造化された配列です

NSDictionary *parentDict=[[NSDictionary alloc]initWithDictionary:nil];
NSString *name=[[NSString alloc]init];
NSArray *table=[[NSArray alloc]initWithArray:nil];
for (NSDictionary * dict in array) {
table=[dict objectForKey:@"tables"];
for (NSDictionary *childDict in table) {
if ([[childDict objectForKey:@"id"]isEqualToString:@"6"]) {
//if your id value is int then use ==6 to check
parentDict=dict;
name=[dict objectForKey:@"name"];
return;
}
}
}