iOS:从字典中的.plist读取数据

 多米音乐_35782132 发布于 2023-02-02 23:30

我想从我的.app目录中的plist中检索数据.我无法弄清楚如何获取子词典数据.例如,我想获得MemoriesDictionary/Memory1/Event1/EventName价值.

字典

我可以通过以下方式获得MemoryCount价值iMemCount:

int iMemCount;

//Do file searching/getting for plist

NSString *plistDirectory = [[NSBundle mainBundle] pathForResource:@"memoryDetails" ofType:@"plist"];
NSLog(@"array: %@",plistDirectory);

NSFileManager *fileManager = [NSFileManager defaultManager];

if ([fileManager fileExistsAtPath: plistDirectory]) //4
{
    NSLog(@"exists");
    NSMutableDictionary *savedStock = [[NSMutableDictionary alloc] initWithContentsOfFile: plistDirectory];

    iMemCount = [[savedStock objectForKey:@"MemoryCount"] intValue];


} else {
    NSLog(@"Does Not Exist");
    iMemCount = 0;
}

Abizern.. 6

NSString *string = savedStock[@"MemoriesDictionary"][@"Memory1"][@"Event1"][@"EventName"];

编辑

你也可以改写:

int iMemCount;
iMemCount = [[savedStock objectForKey:@"MemoryCount"] intValue];

NSInteger iMemCount;
iMemCount = [savedStock[@"MemoryCount"] integerValue];

你真的应该考虑在64位处理器上运行的您的iOS代码的可能性,并使用相应平台的安全类型(NSInteger,CGFloat,CFIndex等)

1 个回答
  • NSString *string = savedStock[@"MemoriesDictionary"][@"Memory1"][@"Event1"][@"EventName"];
    

    编辑

    你也可以改写:

    int iMemCount;
    iMemCount = [[savedStock objectForKey:@"MemoryCount"] intValue];
    

    NSInteger iMemCount;
    iMemCount = [savedStock[@"MemoryCount"] integerValue];
    

    你真的应该考虑在64位处理器上运行的您的iOS代码的可能性,并使用相应平台的安全类型(NSInteger,CGFloat,CFIndex等)

    2023-02-02 23:47 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有