- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
self.connection = nil;
NSString * dataStr = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];
NSArray * lines = [dataStr componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];
NSMutableArray * res = [NSMutableArray arrayWithCapacity:[lines count]];
NSString * line = nil;
Picture * pic = nil;
for (NSUInteger i = 0; i < [lines count]; i++) {
line = (NSString*) [lines objectAtIndex:i];
NSArray * arr = [line componentsSeparatedByString:@","];
pic = [[Picture alloc] init];
pic.pictureId = [[NSDecimalNumber decimalNumberWithString:(NSString *) [arr objectAtIndex:0]] intValue];
pic.title = (NSString*) [arr objectAtIndex:1];
pic.description = (NSString*) [arr objectAtIndex:2];
pic.imageData = (NSData*) [arr objectAtIndex:3];
pic.rate = [[NSDecimalNumber decimalNumberWithString:(NSString*) [arr objectAtIndex:4]] floatValue];
pic.numberOfRate = [[NSDecimalNumber decimalNumberWithString:(NSString*) [arr objectAtIndex:5]] intValue];
pic.numberOfDownload = [[NSDecimalNumber decimalNumberWithString:(NSString*) [arr objectAtIndex:6]] intValue];
pic.numberOfComment = [[NSDecimalNumber decimalNumberWithString:(NSString*) [arr objectAtIndex:7]] intValue];
[res addObject:pic];
[pic release];
}
self.picturesData = res;
//display a image
[self displayAImage];
[dataStr release];
}
I do this but dataStr returned nil, do you think I have problem with encoding?