Ketan Shinde
Ketan Shinde

Reputation: 1847

problem while getting key value for url to data , then to uiimage

I have a URL with tag:

http://ws.cdyne.com/WeatherWS/Images/sunny.gif

When I do like this:

NSURL *url=[NSURL URLWithString:@"http://ws.cdyne.com/WeatherWS/Images/sunny.gif"];

it's getting image in gdb and I am able to download from this URL. But when I write code like this:

NSURL *url=[jsonItem objectForKey:@"PictureURL"];  

(where jsonItem is dictionary and passing it to data and then to UIImage), then it shows an exception.

When I get the value of:

  [jsonItem objectForKey:@"PictureURL"]; 

in gdb then it shows like:

2011-03-15 11:08:16.405 XML[1576:20b] jsonURKL  ..... ...

http://ws.cdyne.com/WeatherWS/Images/thunderstorms.gif   (in next line in gdb)

I need to download through this:

NSURL *url=[jsonItem objectForKey:@"PictureURL"];

I am not able to do that. What could be wrong?

Upvotes: 2

Views: 250

Answers (2)

GameLoading
GameLoading

Reputation: 6708

Url itself one string. so you have to use below code

NSURL *url=[NSURL URLWithString:[jsonItem objectForKey:@"PictureURL"]];
NSData *data = [NSData dataWithContentsOfURL: url];

now setimgge with [UIImage imageWithData: data]; this code

Upvotes: 2

Mayur Birari
Mayur Birari

Reputation: 5835

please do this in following way,

NSURL *url=[NSURL URLWithString:[jsonItem objectForKey:@"PictureURL"]];
NSData *data = [NSData dataWithContentsOfURL: url];
cell.iconImage.image=[UIImage imageWithData: data];

Upvotes: 1

Related Questions