0

私は次のような NSDictionary を持っています:

 data = {
    start = {
        name = "abc";
        age = "123";
        id = AA838DDE;
    };
};

個人の名前、年齢、ID を取得するために辞書を解析するにはどうすればよいですか? ありがとう。

4

3 に答える 3

2
NSString *name = dictionary[@"data"][@"start"][@"name"];
于 2013-11-04T17:03:54.890 に答える
0

試してみませんか:

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);
}
于 2013-11-05T06:55:44.223 に答える
0

新しい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);
于 2013-11-04T17:31:45.887 に答える