[ios]plist 加载

本文详细介绍了如何使用Objective-C语言加载并解析plist文件,包括获取文件路径、创建字典对象以及通过键值访问二级字典的示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

- (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>
 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值