我对NSDictionary的帮助不大。我如何得到1对,如果我有字典,就说“id”的值
NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers error:&error];
它看起来像这样:
感谢您的帮助。
答案 0 :(得分:9)
最短路:
NSNumber *number = allCourses[@"semacko"][@"id"];
答案 1 :(得分:2)
试试这个:
NSDictionary *allCourses = [NSJSONSerialization JSONObjectWithData:allCoursesData options:NSJSONReadingMutableContainers error:&error];
[allCourses enumerateKeysAndObjectsUsingBlock: ^(id key, id obj, BOOL *stop) {
// do something with key and obj
}];
答案 2 :(得分:1)
NSDictionary *semacko = [allCourses objectForKey:@"semacko"];
NSNumber *number = [semacko objectForKey:@"id"];
答案 3 :(得分:1)
NSNumber *number = allCourses[@"semacko"][@"id"];
或者如果你想迭代所有对象:
for(NSDictionary* course in allCourses) {
NSNumber *number = course[@"id"];
}
答案 4 :(得分:1)
NSString *name =[[NSString alloc]initWithFormat:@"%@",[Dictionaryname objectForKey:@"key"]];
通过此代码,您可以访问与objectforkey关键字
中指定的键对应的值答案 5 :(得分:0)
您可以尝试:
NSNumber *courseID = [allCourses valueForKeyPath:@"semacko.id"];
设置值:
- setValue:forKeyPath: