---
title: "[ios]plist 加载"
author: "119568242"
date: "2012-10-16T18:25:06Z"
tags: []
categories: ["移动开发"]
slug: "ios-plist"
draft: false
lastmod: "2012-10-16T18:25:06Z"
id: 1699694
url: "https://poolo.iteye.com/blog/1699694"
---

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