How to get key / value pair from NSDictionary?

I need a little help in NSDictionary. How can I get 1 pair, let's say the value for "id" if I have a dictionary

NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers error:&error];

and looks like this:

NSDictionary allCourses

Thank you for your help.

+3
source share
6 answers

The shortest way:

NSNumber *number = allCourses[@"semacko"][@"id"];
+9
source

Try the following:

NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers error:&error];
        [allCourses enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
    // do something with key and obj
}];
+2
source
NSDictionary *semacko = [allCourses objectForKey:@"semacko"];
NSNumber *number = [semacko objectForKey:@"id"];
+1
NSNumber *number = allCourses[@"semacko"][@"id"];

:

for(NSDictionary* course in allCourses) {
    NSNumber *number = course[@"id"];
}
+1
NSString *name =[[NSString alloc]initWithFormat:@"%@",[Dictionaryname objectForKey:@"key"]];

, , objectforkey

+1

:

NSNumber *courseID = [allCourses valueForKeyPath:@"semacko.id"];

:

- setValue:forKeyPath:
0

All Articles