文件内容不在ios中工作的词典
我正在尝试从ios中的plist获取字典。问题是代码不起作用。它在不同的函数中起作用,但在这个函数中不起作用文件内容不在ios中工作的词典,ios,objective-c,cocoa-touch,nsdictionary,jailbreak,Ios,Objective C,Cocoa Touch,Nsdictionary,Jailbreak,我正在尝试从ios中的plist获取字典。问题是代码不起作用。它在不同的函数中起作用,但在这个函数中不起作用 NSDictionary* pdata=[NSDictionary dictionaryWithContentsOfFile:datapath]; 文件存在于路径中,但由于某些原因它无法工作。当我尝试打印字典时,我得到null 编辑:这是我的路径/private/var/mobile/Applications/F4D5EFE8-58FC-4179-9492-4C4F9FD01024
NSDictionary* pdata=[NSDictionary dictionaryWithContentsOfFile:datapath];
文件存在于路径中,但由于某些原因它无法工作。当我尝试打印字典时,我得到null
编辑:这是我的路径/private/var/mobile/Applications/F4D5EFE8-58FC-4179-9492-4C4F9FD01024/Library/Preferences/abc.def.ghi.plist。这是一个越狱应用程序,我可以在单独的位置为另一个应用程序成功执行此操作。这对您来说必须有效
NSString *aStr=[[NSBundle mainBundle] pathForResource:@"Property List" ofType:@"plist"];
NSURL *aUrl=[NSURL fileURLWithPath:aStr];
NSDictionary *aDict=[[NSDictionary alloc] initWithContentsOfURL:aUrl];
试试这个
NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]
pathForResource:@"example" ofType:@"plist"]isDirectory:NO]];
NSLog(@"data is %@",dict);
这应该行得通
NSString *plistFileUrl=[[NSBundle mainBundle] pathForResource:@"someplistFile" ofType:@"plist"];
NSURL *url=[NSURL fileURLWithPath:plistFileUrl];
NSDictionary *aDict=[[NSDictionary alloc] initWithContentsOfURL:url];
试试这个
//Local mainbundle
NSString *path = [[NSBundle mainBundle] bundlePath];
NSString *filePath = [path stringByAppendingPathComponent:@"Contents.plist"];
NSMutableDictionary *dictContent = [NSMutableDictionary dictionaryWithContentsOfFile:filePath];
NSLog(@"%@",dictContent);
///DocumentsDirectory
NSMutableDictionary *dictItem=[[NSMutableDictionary alloc]init];
[dictItem setObject:@"ravi" forKey:@"name"];
NSArray *paths = NSSearchPathForDirectoriesInDomains( NSDocumentDirectory,
NSUserDomainMask, YES);
NSString *documentsDirectoryPath = [paths objectAtIndex:0];
NSString *docFilePath = [documentsDirectoryPath
stringByAppendingPathComponent:@"data.plist"];
[dictItem writeToFile:docFilePath atomically: YES];
NSMutableDictionary *dictContent1 = [NSMutableDictionary dictionaryWithContentsOfFile:docFilePath];
NSLog(@"%@",dictContent1);
也发布您的数据路径代码。。这可能有助于我们正确回答。您可以发布用于创建数据路径的文件内容或代码吗?请检查此[链接][1],也许它可以帮助[1]:您需要检查写入的plist根文件是否为字典或数组返回异常(***-[NSURL initFileURLWithPath::nil字符串参数)检查名称。我已经创建并测试了abc.def.ghi.plist,它在这里对我有用。