0

I am getting image From JSON url.I tried like this but i did't not get image

  NSMutableArray *al=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
        NSLog(@"all NSMutable2%@",al);
        NSDictionary *dict = [al objectAtIndex:1];
            NSString *title=[dict objectForKey:@"dealimage"];
            NSLog(@"all DIC%@",title);

        NSData *data1 = [[NSData alloc] initWithData:[NSData
                                                     dataFromBase64String:title]];
            NSLog(@"********************************%@",data1);
        NSData* data = [Base64 decode:title ];
        UIImage *image = [UIImage imageWithData:data];

        dig=[[UIImageView alloc]initWithImage:image];
        [self.view addSubview:dig];
        dig.frame = CGRectMake(0, 25 , 150,150);

My idea is first NSString data converted to NSData and Then NSData pass to UIImage.But No luck So Please give me any idea

1
  • Show the data you're logging. Are you base64 decoding twice there? What are those methods you're calling for base64? Commented Jul 9, 2014 at 7:25

1 Answer 1

1
#import "NSData+Base64.h"

//Creating the data from your base64String
 NSData *data = [[NSData alloc] initWithData:[NSData dataFromBase64String: title]];

//Now data is decoded. You can convert them to UIImage
UIImage *image = [UIImage imageWithData:data];

 dig=[[UIImageView alloc]initWithImage:image];
 dig.frame = CGRectMake(0, 25 , 150,150);
 [self.view addSubview:dig];
Sign up to request clarification or add additional context in comments.

4 Comments

you were decoded in 2 times , that y u can't get in the image ,
thanks for Reply observed one thing yes decoded in 2 times but i passed only one NSdata to UIImage
in after this line u were get the data NSData* data = [Base64 decode:title ];
i placed as you said but i not getting image so Please give me any idea

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.