2

我在 plist 文件中有 20 个字典。我需要用他们的名字编辑一个特定的字典,但真的不知道如何做到这一点。我需要获取值并对 SearchCountry Dictionary 进行更改。

如何编辑特定的字典值?

在此处输入图像描述

4

2 回答 2

1

尝试使用NSPorpertyListSerialization对属性列表进行复杂迭代。

否则,您可能已尝试使用以下代码访问特定字典

NSString*  plistPath = [[NSBundle mainBundle] pathForResource:@"yourPList" 
                                                     ofType:@"plist"];
NSDictionary* plistDict = [NSDictionary dictionaryWithContentsOfFile:plistPath]; 
// plistDict contains all the dictionaries inside it now, you could try to access the particular inside the plistDict

id *searchKey = [plistDict objectForKey:@"SearchCountry"]; 
//OR
NSString* searchKeys = [plistDict valueForKeyPath:@"SearchCountry"];
于 2013-03-25T21:36:36.240 回答
1

得到一个像这样的子字典:

NSMutableDictionary *plist = [[NSMutableDictionary alloc] initWithContentsOfFile:plistFilename];
NSMutableDictionary *searchCountry = [plist objectForKey:@"SearchCountry"];

像这样更改其中一个值:

 [searchCountry setValue:@"Cleveland" forKey:@"searchcity"];

像这样保存它:

BOOL success = [plist writeToFile:plistFilename atomically:YES];
于 2013-03-25T21:43:07.287 回答