【发布时间】:2013-03-25 10:02:03
【问题描述】:
我有一个字典,其中的值如图所示,我有一个整数值的 book id 。如何检查 bookid 是否匹配?
这是我的检查代码
NSMutableDictionary *plistdictionary = [[NSMutableDictionary alloc]initWithContentsOfFile:metaDataPath];
NSMutableArray *notes=[plistdictionary objectForKey:@"usernotes"];
NSLog(@"notes value %@",notes);
NSArray *CollectingBookid=[[NSArray alloc]init];
CollectingBookid=[notes valueForKey:@"bookid"];
NSArray *CollectingPages=[[NSArray alloc]init];
CollectingPages=[notes valueForKey:@"pagenumber"];
NSArray *CollectingNotes=[[NSArray alloc]init];
CollectingNotes=[notes valueForKey:@"notes"];
NSLog(@"collection of book id%@",CollectingBookid);
NSString *bookid=@"95";
NSString *page=@"1";
int c=[CollectingBookid count];
for(int i=0;i<c;i++)
{
NSString *singleBookids=[CollectingBookid objectAtIndex:i];
NSString *singlePage=[CollectingPages objectAtIndex:i];
if([singleBookids isEqualToString:bookid])
{
if([singlePage isEqualToString:page])
{
NSMutableArray *CompleteUserNotes=[[NSMutableArray alloc]init];
CompleteUserNotes=[CollectingNotes objectAtIndex:i];
NSLog(@"Selected Notes%@",CompleteUserNotes);
}
}
}
【问题讨论】:
-
为什么 bookid 是 pList 中的字符串?您想将整数与整数进行比较吗?或者你想比较字符串和字符串?
-
如何在字典中添加整数值?
-
这些与您的图片不匹配: NSArray *CollectingBookid=[[NSArray alloc]init]; CollectingBookid=[notes valueForKey:@"bookid"]; NSArray *CollectingPages=[[NSArray alloc]init]; CollectingPages=[notes valueForKey:@"pagenumber"]; NSArray *CollectingNotes=[[NSArray alloc]init]; CollectingNotes=[notes valueForKey:@"notes"];
标签: ios xcode nsarray plist nsdictionary