Iphone 删除键值后将字典转换为数组

Iphone 删除键值后将字典转换为数组,iphone,ios,ios5,Iphone,Ios,Ios5,我需要从数组的每个索引中删除前三个键值。我所做的是 for (int i=0; i<[normalscoringarray count]; i++) { NSDictionary *dictionary = [normalscoringarray objectAtIndex:i]; NSMutableDictionary *mutableDictionary = [dictionary mutableCopy];

我需要从数组的每个索引中删除前三个键值。我所做的是

  for (int i=0; i<[normalscoringarray count]; i++)        
    { 

        NSDictionary *dictionary = [normalscoringarray objectAtIndex:i];

        NSMutableDictionary *mutableDictionary = [dictionary mutableCopy];

        [mutableDictionary removeObjectForKey:@"cn"];
        [mutableDictionary removeObjectForKey:@"gdate"];
        [mutableDictionary removeObjectForKey:@"gid"];

         NSLog(@"mutableDictionary.....%@",mutableDictionary);

     NSMutableArray *remainingArray = [[NSMutableArray alloc]init];

        for (id item in mutableDictionary) {
            [remainingArray setArray:[mutableDictionary objectForKey:item]];
        }
       }
我想要的方式

    normalscoringarray....(
    id = 1,
    p1nets = "3,3,4,4,2,2,2,4,3,3,4,2,5,3,5,4,3,4||27||33||60",
    p1nh = "BP||14||1",
    p1score = "4,4,5,5,3,3,3,5,4,4,5,3,5,3,6,4,4,5||36||39||75||61",
    p1spoints = "3,3,3,2,3,4,3,3,3,3,2,4,1,2,2,1,3,3||27||21||48",
    p2nets = "4,3,4,4,3,4,2,5,4,4,3,3,4,3,6,3,4,4||33||34||67",
    p2nh = "DG||18||2",
    p2score = "5,4,5,5,4,5,3,6,5,5,4,4,5,4,7,4,5,5||42||43||85||67",
    p2spoints = "2,3,3,2,2,2,3,2,2,2,3,3,2,2,1,2,2,3||21||20||41",
    p3nets = "4,3,6,4,2,3,2,4,5,4,3,5,6,3,4,3,5,6||33||39||72",
    p3nh = "NM||24||3",
    p3score = "6,5,7,6,4,5,3,6,6,5,5,6,7,4,5,4,6,7||48||49||97||73",
    p3spoints = "2,3,1,2,3,3,3,3,1,2,3,1,0,2,3,2,1,1||21||15||36",
    p4nets = "3,4,5,4,2,3,3,5,3,4,3,5,4,3,5,3,4,6||32||37||69";
    p4nh = "KS||20||4";
    p4score = "5,5,6,5,3,5,4,6,4,5,5,6,5,4,6,4,5,7||43||47||90||70",
    p4spoints = "3,2,2,2,3,3,2,2,3,2,3,1,2,2,2,2,2,1||22||17||39",
)

希望这对你有帮助

另外,当你不再需要remainingArray时,也别忘了发布它。Ketan,你在问题中问过你想要结果的方式,但我不明白你为什么需要这样的格式?因为你们可以通过它的键直接访问任何值。实际上,我想在每个键上应用“for循环”来进行检查,这就是为什么我需要数组中的所有键…但我没有得到它。
    normalscoringarray....(
    id = 1,
    p1nets = "3,3,4,4,2,2,2,4,3,3,4,2,5,3,5,4,3,4||27||33||60",
    p1nh = "BP||14||1",
    p1score = "4,4,5,5,3,3,3,5,4,4,5,3,5,3,6,4,4,5||36||39||75||61",
    p1spoints = "3,3,3,2,3,4,3,3,3,3,2,4,1,2,2,1,3,3||27||21||48",
    p2nets = "4,3,4,4,3,4,2,5,4,4,3,3,4,3,6,3,4,4||33||34||67",
    p2nh = "DG||18||2",
    p2score = "5,4,5,5,4,5,3,6,5,5,4,4,5,4,7,4,5,5||42||43||85||67",
    p2spoints = "2,3,3,2,2,2,3,2,2,2,3,3,2,2,1,2,2,3||21||20||41",
    p3nets = "4,3,6,4,2,3,2,4,5,4,3,5,6,3,4,3,5,6||33||39||72",
    p3nh = "NM||24||3",
    p3score = "6,5,7,6,4,5,3,6,6,5,5,6,7,4,5,4,6,7||48||49||97||73",
    p3spoints = "2,3,1,2,3,3,3,3,1,2,3,1,0,2,3,2,1,1||21||15||36",
    p4nets = "3,4,5,4,2,3,3,5,3,4,3,5,4,3,5,3,4,6||32||37||69";
    p4nh = "KS||20||4";
    p4score = "5,5,6,5,3,5,4,6,4,5,5,6,5,4,6,4,5,7||43||47||90||70",
    p4spoints = "3,2,2,2,3,3,2,2,3,2,3,1,2,2,2,2,2,1||22||17||39",
)
NSMutableArray *remainingArray = [[NSMutableArray alloc]init];

for (int i=0; i<[normalscoringarray count]; i++)        
{
    NSMutableDictionary *mutableDictionary = [[NSMutableDictionary alloc] initWithDictionary:[normalscoringarray objectAtIndex:i]]; //each time alloc and init with contents of normalscoringarray

     //Remove values for keys
    [mutableDictionary removeObjectForKey:@"cn"];
    [mutableDictionary removeObjectForKey:@"gdate"];
    [mutableDictionary removeObjectForKey:@"gid"];

    [remainingArray addObject:mutableDictionary]; //add mutableDictionary to remainingArray

    [mutableDictionary release]; //free mutableDictionary
}

//finally print contents of remainingArray
NSLog(@"normalscoringarray:\n%@",[remainingArray description]);
for (int i=0; i<[normalscoringarray count]; i++)        
{       
    NSMutableDictionary *dictionary = [NSMutableDictionary dictionaryWithDictionary:[normalscoringarray objectAtIndex:i]];


    [dictionary removeObjectForKey:@"cn"];
    [dictionary removeObjectForKey:@"gdate"];
    [dictionary removeObjectForKey:@"gid"];

        [normalscoringarray replaceObjectAtIndex:i withObject:dictionary];
 }