NSString *plist=[[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
NSDictionary *dict=[[NSDictionary alloc] initWithContentsOfFile:plist];
NSString *stringValue=dict[@"URL"][@"reg"];
编辑:了解以下内容非常重要:
在上面dict
本身就是objectForKey:@"Root"
我/我们试图找到[@"Root"][@"URL"][@"reg"]
不存在的。
因此,对于命名约定(它存储的内容)的可读性,它应该是:
NSString *plist=[[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
NSDictionary *rootDict=[[NSDictionary alloc] initWithContentsOfFile:plist];
NSString *stringValue=dict[@"URL"][@"reg"];
甚至
NSString *plist=[[NSBundle mainBundle] pathForResource:@"config" ofType:@"plist"];
NSString *stringValue=[[NSDictionary alloc] initWithContentsOfFile:plist][@"URL"][@"reg"];