I have one Url :http://192.168.3.178:8090/SaveDollar/rest/deals/dealimages
I am trying Get the Image from Url.
What I tried:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSMutableArray *al=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
NSLog(@"all NSMutable2");
for (NSDictionary *diction in al)
{
Name.text=[diction valueForKey:@"dealImage"];
NSString* str = Name.text;
NSLog(@"%@dataImage is ",str);
NSData* data = [str dataUsingEncoding:NSUTF8StringEncoding];
NSUInteger len = data.length;
uint8_t *bytes = (uint8_t *)[data bytes];
NSMutableString *result = [NSMutableString stringWithCapacity:len * 3];
[result appendString:@"["];
for (NSUInteger i = 0; i < len; i++)
{
if (i)
{
[result appendString:@","];
}
[result appendFormat:@"%d", bytes[i]];
}
[result appendString:@"]"];
NSLog(@"result%@",result);
NSLog(@"uint8_t%s",bytes);
NSMutableData *newData = [NSMutableData new];
NSScanner *theScanner = [NSScanner scannerWithString: result];
theScanner.charactersToBeSkipped = [NSCharacterSet characterSetWithCharactersInString:@"[],"];
while ([theScanner isAtEnd] == NO) {
int a;
[theScanner scanInt:&a];
uint8_t b = a;
[newData appendBytes:(const void *)&b length:1];
}
UIImage *newImage = [UIImage imageWithData:newData];
UIImageView *imageView=[[UIImageView alloc] initWithImage:newImage];
imageView.frame = CGRectMake(0, 25 , 400,150);
[self.view addSubview:imageView];
}
}
First I am converted String to NSdata and then NSData converted Byte data Second I am Converted Byte data to NSdata and then NSdata is pass to the UIImage
My Problem : Image not Displaying but Database have image so Please Give me any idea about my problem
JSON FormatViewer like this:
JSON
0
dealImageId : 1
dealImage : "WjQyNDAzMTM2Mzk2NTMxMzE="
dealId : 2
createdDate : 1393871400000
modifiedDate : 1399314600000
createdUserId : 2
modifiedUserId : 4
dealPosted
deleted : true
1
dealImageId : 3
dealImage : "5mQ4ZmZlMTdkY2E0NTc4Njk2NjAwMDA0OTQ5MmEwMDA4MDAwMDAwMGUwMDBlMDEwMjAwMWUwMDAwMDBiNjAwMDAwMDBmMDEwMjAwMTAwMDAwMDBkNDAwMDAwMDEwMDEwMjAwMGEwMDAwMDBlNDAwMDAwMDEyMDEwMzAwMDEwMDAwMDAwMTAwMDAwMDIwMjgyZTJlMmUyOQ=="
dealId : 1
createdDate : 1391365800000
modifiedDate : 1391365800000
createdUserId : 1
modifiedUserId : 2
dealPosted
deleted : false