私は次のような NSDictionary を持っています:
data = {
start = {
name = "abc";
age = "123";
id = AA838DDE;
};
};
個人の名前、年齢、ID を取得するために辞書を解析するにはどうすればよいですか? ありがとう。
私は次のような NSDictionary を持っています:
data = {
start = {
name = "abc";
age = "123";
id = AA838DDE;
};
};
個人の名前、年齢、ID を取得するために辞書を解析するにはどうすればよいですか? ありがとう。
NSString *name = dictionary[@"data"][@"start"][@"name"];
試してみませんか:
int arrCount = [[[dictionaryObject valueForKey:@"data"] objectForKey:@"start"] count];
for(int i = 0 ; i < arrCount ; i++)
{
NSString *strName = [[[[dictionaryObject objectForKey:@"data"]
objectForKey:@"start"]
objectAtIndex:i]
objectForKey:@"name"];
NSString *strAge = [[[[dictionaryObject objectForKey:@"data"]
objectForKey:@"start"]
objectAtIndex:i]
objectForKey:@"age"];
NSString *strID = [[[[dictionaryObject objectForKey:@"data"]
objectForKey:@"start"]
objectAtIndex:i]
objectForKey:@"id"];
NSLog(@"%@ - %@ - %@", strName, strAge, strID);
}
新しいObjective-C構文が嫌いなので、別の回答を追加します(申し訳ありません@Raphael Olivieira)
NSString *name = [[[[dictionary objectForKey:@"data"] objectForKey:@"start"] objectAtIndex:0] objectForKey:@"name"];
NSLog(@"%@", name);
前の回答よりも長いですが、自分が何をしているのかを知っていて、C でコーディングしていません。
ところで、他の構文を使用して:
NSString *name = dictionary[@"data"][@"start"][0][@"name"];
NSLog(@"%@", name);