2010-02-26 22 views
0

代碼:如何獲取字串值的NSMutableArray的

[self.menuList addObject:[NSDictionary dictionaryWithObjectsAndKeys: 
             NSLocalizedString(@"PropertySubtype2fTitle", @""), 
             kTitleKey, 
             publishNoOfRoomsViewController, 
             kViewControllerKey, nil]]; 

菜單列表是一個的NSMutableArray。

我想稍後閱讀PropertySubtype2fTitle本地化的字符串中的代碼,就像:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 

回答

8

要提取的NSDictionary的條目,就可以使用

[NSDictionary objectForKey:(id)keyValue]
。要從NSArray/NSMutableArray獲取條目,可以使用
[NSArray objectAtIndex:(NSUInteger)index]
。結合並應用於您的示例應該是:
NSString *title = [[menuList objectAtIndex:index] objectForKey:kTitleKey];
而索引將是一個無符號整數(NSUInteger)。

0

爲什麼不直接使用NSMutableDictionary

例如:

NSData *getData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strURL]]; 
NSError *errorData; 
NSMutableDictionary *dicData = [NSJSONSerialization 
            JSONObjectWithData:getData 
            options:NSJSONReadingMutableContainers 
            error:&errorData]; 

if(errorData) 
{ 
    NSLog(@"%@", [errorData localizedDescription]); 
} 
else { 

    NSString *title = [[dicData[@"items"] objectAtIndex:1] objectForKey:@"titlekey"]; 
    NSLog(@"titlekey %@",title); 
} 
相關問題