Reputation: 716
I need little help with NSDictionary. How can I get 1 pair, lets say a value for "id" if I have dictionary
NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers error:&error];
and it looks like this:
Thanks for Your help.
Upvotes: 3
Views: 12940
Reputation: 16160
You can try:
NSNumber *courseID = [allCourses valueForKeyPath:@"semacko.id"];
For setting value:
- setValue:forKeyPath:
Upvotes: 0
Reputation: 1415
NSString *name =[[NSString alloc]initWithFormat:@"%@",[Dictionaryname objectForKey:@"key"]];
by this code you can access the value that corresponds to the key that specified in the objectforkey keyword
Upvotes: 1
Reputation: 1669
Try this:
NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers error:&error];
[allCourses enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
// do something with key and obj
}];
Upvotes: 2
Reputation: 337
NSNumber *number = allCourses[@"semacko"][@"id"];
or if you want to iterate all objects:
for(NSDictionary* course in allCourses) {
NSNumber *number = course[@"id"];
}
Upvotes: 1
Reputation: 1843
NSDictionary *semacko = [allCourses objectForKey:@"semacko"];
NSNumber *number = [semacko objectForKey:@"id"];
Upvotes: 1