Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何从密钥为x的NSDictionary创建新的NSDictionary_Ios_Json - Fatal编程技术网

Ios 如何从密钥为x的NSDictionary创建新的NSDictionary

Ios 如何从密钥为x的NSDictionary创建新的NSDictionary,ios,json,Ios,Json,我有一个应用程序,通过web api从mysql服务器获取一些json数据,如下所示: [[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"streamGames", @"command", nil] onCompletion:^(NSDictionary *json) { //got stream [[API sharedInstance]

我有一个应用程序,通过web api从mysql服务器获取一些json数据,如下所示:

[[API sharedInstance] commandWithParams:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"streamGames", @"command", nil] onCompletion:^(NSDictionary *json) {

    //got stream

     [[API sharedInstance] setGames:[json objectForKey:@"result"]];
这给了我:

{
    awayScor = 3;
    data = "2014-04-11";
    gameType = 1;
    homeScor = 2;
    homeTeam = "Herning Blue Fox";
    time = "21:00";
},
    {
    awayScor = 1;
    data = "2014-04-08";
    gameType = 2;
    homeScor = 2;
    homeTeam = "SønderjyskE";
    time = "19:00";
},

现在,我想做的是制作一个新的NSDictionary,其中我只添加数据,比如gameType=1,这样我就有了一个新的NSDictionary,用于蚀刻gameType。

如果我正确理解了这个问题

NSArray *games; // Get this from somewhere
NSMutableDictionary *gameTypes = [NSMutableDictionary dictionary];

for (NSDictionary *game in games) {
    NSNumber *gameType = game[@"gameType"];
    NSMutableArray *gamesForType = gameTypes[gameType];
    if (!gamesForType) {
        gamesForType = [NSMutableArray array];
        gameTypes[gameType] = gamesForType;
    }
    [gamesForType addObject:game];
}
现在,
gameTypes
将是一个游戏类型字典,用于该类型的数组游戏