与plist的奇怪错误 [英] Strange bug with plist
本文介绍了与plist的奇怪错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试读取我的plist时,我遇到了一个非常奇怪的错误. 我的列表如下:
I got a very strange bug when I'm trying to read my plist. My plist looks like :
Root (Array)
Item 0 (Dictionary)
title (String)
我想在日志中显示title
,所以我做了下面的代码:
I want to display title
in the log, so I did the code bellow:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
NSString *path = [basePath stringByAppendingPathComponent:@"data.plist"];
NSMutableDictionary *dict = [[NSDictionary dictionaryWithContentsOfFile:path] mutableCopy];
NSLog(@"%@", [dict objectForKey:@"title"]);
NSLog(@"Path to plist: %@", path);
使用此代码,NSLog(@"%@", [dict objectForKey:@"title"]);
等于"(null)
" ...
With this code, NSLog(@"%@", [dict objectForKey:@"title"]);
is equal to "(null)
"...
我的plist位于应用程序的documents文件夹中,而path
的日志返回指向我的plist的正确路径.
My plist is in my app's documents folder, and the log of path
return the good path to my plist.
请帮助我:)
推荐答案
plist的根是一个数组,但是您将其读入字典中,那是行不通的.
The root of your plist is an array but you read it into a dictionary, thats won't work.
您应该:
- 将plist读入数组
- 获取项目0(objectAtIndex:0)->这是一本字典
- 在此词典上,您可以执行objectForKey ...
这篇关于与plist的奇怪错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文