0
-(void)downloadResult:(id)data
{
   if([data isKindOfClass:[NSArray class]])
   {
       if ([data count]==3) 
       {
           if ([dataResultDictionary count]) 
           {
                [[dataResultDictionary objectForKey:[data objectAtIndex:0]] addObject:[NSMutableArray arrayWithObjects:[data objectAtIndex:1],[data lastObject], nil]];
           }
           else
           {
               [dataResultDictionary setObject:[NSMutableArray arrayWithObject:[NSMutableArray arrayWithObjects:[data objectAtIndex:1],[data lastObject], nil]] forKey:[data objectAtIndex:0]];
           }
           if([dataResultDictionary count])
           {
                if ([[dataResultDictionary objectForKey:[data objectAtIndex:0]] count] == requiredResultCount) 
                 {
                    [downloadControlQueue cancelAllOperations];
                    [downloadControlQueue release];
                    downloadControlQueue = nil;
                    processing = YES;
                    [self procesResultData];
                }
            }

      }
      else
      {
            BOOL errorResult = TRUE;

            if ([data count]) 
            {
                        if ([[data lastObject] isKindOfClass:[NSMutableDictionary class]]) {
                            if ([[data lastObject] count]) {
                                if ([[[[data lastObject] allValues] objectAtIndex:0] count]) {

                                    [dataResultDictionary setObject:[data lastObject] forKey:[data objectAtIndex:0]];
                                    errorResult = false;
                }

               }
          }
       }

            if(errorResult)
            {
                [dataResultDictionary setObject:@"" forKey:[data objectAtIndex:0]];
            }
            if ([dataResultDictionary count] == requiredResultCount) {
                [downloadControlQueue cancelAllOperations];
                [downloadControlQueue release];
                downloadControlQueue = nil;
                processing = YES;
                [self procesResultData];

            }
            }
        }


    }

我正在从服务器获取数据。我想在图像中显示 % 值的下载结果。但我要崩溃了。最初,这种方法是可行的。我在图像中显示了高达 70% 的数据,但其余部分已崩溃。帮帮我

4

2 回答 2

1

根据 rakeshNS 的建议,回答您的问题,这似乎[dataResultDictionary objectForKey:[data objectAtIndex:0]]不是NSMutableArray. 相反,它是一个NSString.

为什么要尝试addObject:解析数组,顺便说一句,它是不可变的(NSArray)?你真的应该重新考虑解析逻辑。如果需要,创建一个单独的模型类来存储解析的数据。您可以在此模型类中创建可变数组并存储值。

于 2013-09-06T07:55:19.080 回答
0

在您的情况下[dataResultDictionary objectForKey:[data objectAtIndex:0]],它不是数组,而是 NSString。所以你得到了例外。尝试

if ([dataResultDictionary count]) {
     if([[dataResultDictionary objectForKey:[data objectAtIndex:0]] isKindOfClass:[NSArray class]]){
          [[dataResultDictionary objectForKey:[data objectAtIndex:0]] addObject:[NSMutableArray arrayWithObjects:[data objectAtIndex:1],[data lastObject], nil]];
     }
}
else
{
     [dataResultDictionary setObject:[NSMutableArray arrayWithObject:[NSMutableArray arrayWithObjects:[data objectAtIndex:1],[data lastObject], nil]] forKey:[data objectAtIndex:0]];
}
于 2013-09-06T07:48:32.263 回答