我创建了一个 plist 文件,其中包含一个包含另一个数组的单个数组。每个数组包含四个字典。我已经尝试了很多从 plist 文件中读取数据。但无法获取数据。我的 plist 文件的代码在这里
<plist version="1.0">
<dict>
<key>Root</key>
<array>
<array>
<dict>
<key>name</key>
<string>Czech Republic</string>
<key>imagename</key>
<string>czechrepublic.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Greece</string>
<key>imagename</key>
<string>greece.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Poland</string>
<key>imagename</key>
<string>poland.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Russia</string>
<key>imagename</key>
<string>russia.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
</array>
<array>
<dict>
<key>name</key>
<string>Denmark</string>
<key>imagename</key>
<string>denmark.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Germany</string>
<key>imagename</key>
<string>germany.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Netherlands</string>
<key>imagename</key>
<string>netherlands.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Portugal</string>
<key>imagename</key>
<string>portugal.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
</array>
<array>
<dict>
<key>name</key>
<string>Croatia</string>
<key>imagename</key>
<string>croatia.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Italy</string>
<key>imagename</key>
<string>italy.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Republic of Ireland</string>
<key>imagename</key>
<string>ireland.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Spain</string>
<key>imagename</key>
<string>spain.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
</array>
<array>
<dict>
<key>name</key>
<string>England</string>
<key>imagename</key>
<string>england.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>France</string>
<key>imagename</key>
<string>france.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Sweden</string>
<key>imagename</key>
<string>sweden.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
<dict>
<key>name</key>
<string>Ukraine</string>
<key>imagename</key>
<string>ukraine.png</string>
<key>url</key>
<string>www.google.com</string>
</dict>
</array>
</array>
</dict>
</plist>
并且用于从此 plist 中读取的代码是
NSArray *paths = NSSearchPathForDirectoriesInDomains (NSDocumentDirectory, NSUserDomainMask, YES);
// get documents path
NSString *documentsPath = [paths objectAtIndex:0];
// get the path to our Data/plist file
NSString *plistPath = [documentsPath stringByAppendingPathComponent:@"Data.plist"];
// check to see if Data.plist exists in documents
if (![[NSFileManager defaultManager] fileExistsAtPath:plistPath])
{
// if not in documents, get property list from main bundle
plistPath = [[NSBundle mainBundle] pathForResource:@"Data" ofType:@"plist"];
}
NSMutableDictionary *dict = [NSMutableDictionary alloc] initWithContentsOfFile:plistPath;
NSMutableArray *array = [dict objectForKey:@"Root"];
数组为空。