2 exit door eXit_door 于 2013.07.19 13:44 提问

获取dictionary指定关键字的值

数据如下,我想不循环获取 names= app,app1,app2这种。应该怎么实现?

(
        {
        date = "12/12/12";
        name = app;
    },
        {
        date = "11/02/12";
        name = app1;
    },
        {
        date = "14/05/12";
        name = app2;
    }
)

2个回答

Heartmei0508
Heartmei0508   2013.07.19 14:03

你的问题不具体,程序代码没看明白,写清楚一点哦?

eXit_door
eXit_door 但是最好不要用到循环算法……谢谢拉
4 年多之前 回复
eXit_door
eXit_door 就是上述数据中,我想得到结果:names= app,app1,app2,怎么实现?
4 年多之前 回复
redCoral_
redCoral_   2013.07.19 15:00
NSString *str=[[array1 valueForKeyPath:@"name"] componentsJoinedByString:@","];
NSLog(@"desired string:%@",str);


NSMutableDictionary *dict = [[NSMutableDictionary alloc]init];
    [dict setObject:@"app" forKey:@"name"];

    NSMutableDictionary *dict1 = [[NSMutableDictionary alloc]init];
    [dict1 setObject:@"app1" forKey:@"name"];


    NSMutableDictionary *dict2 = [[NSMutableDictionary alloc]init];
    [dict2 setObject:@"app2" forKey:@"name"];
    NSArray *array1 = [[NSArray alloc]initWithObjects:dict,dict1,dict2, nil];

    NSString *str=[[array1 valueForKeyPath:@"name"] componentsJoinedByString:@","];
    NSLog(@"desired string:%@",str);

    O/P:- app,app1,app2
Csdn user default icon
上传中...
上传图片
插入图片