Reputation: 1
"weatherIconUrl": [
{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0001_sunny.png"
}
],
this is my json data i can able to fetch data in text type but i can't able to fetch image url from weatherIconUrl array
Upvotes: 0
Views: 1538
Reputation: 11276
Its quite easy,
NSError *jsonParsingError = nil;
NSArray *weatherArray = [NSJSONSerialization JSONObjectWithData:yourResponseData options:0 error:&jsonParsingError];
NSLog(@"weatherArray : %@", weatherArray);
NSString *weatherIconImageURL = [[weatherArray objectAtIndex:0] objectForKey:@"weatherIconUrl"]];
NSLog(@"weatherIconImageURL : %@", weatherIconImageURL);
Upvotes: 0
Reputation: 47069
Use following code of line for get value of key @"value"
NSString * imgURLString = [[[myMaindictonary objectForKey:@"weatherIconUrl"] objectAtIndex:0] objectForKey:@"value"];
And convert this string to URL
NSURL *myURL = [NSURL URLWithString:[imgURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
And you can also get image from this URL by
UIImage *myImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:myURL]];
Upvotes: 2