- (void)viewDidLoad
{
[super viewDidLoad];
NSString *Plist=[[NSBundle mainBundle] pathForResource:@"studentList" ofType:@"plist"];
//通过文件名(资源)获取路径
NSDictionary *dt=[[NSDictionary alloc]initWithContentsOfFile:Plist];
//通过通过文件创建字典。
NSDictionary *studentD=[dt objectForKey:@"student"];
//通过通过key找到二级字典
self.nameContent.text=(NSString *)[studentD objectForKey:@"name"];
// NSLog(@"%@",studentPlist);
// Do any additional setup after loading the view, typically from a nib.
}
plist文件
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>student</key> <dict> <key>age</key> <string>22</string> <key>sex</key> <string>boy</string> <key>name</key> <string>poolo</string> </dict> </dict> </plist>
本文详细介绍了如何使用Objective-C语言加载并解析plist文件,包括获取文件路径、创建字典对象以及通过键值访问二级字典的示例。
227

被折叠的 条评论
为什么被折叠?



