"weatherIconUrl": [
{
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0001_sunny.png"
}
],
这是我的json数据,我能够以文本类型获取数据,但我无法从weatherIconUrl数组中获取图像网址
答案 0 :(得分:2)
使用以下代码行获取密钥@"value"
NSString * imgURLString = [[[myMaindictonary objectForKey:@"weatherIconUrl"] objectAtIndex:0] objectForKey:@"value"];
并将此字符串转换为网址
NSURL *myURL = [NSURL URLWithString:[imgURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
您还可以通过
从此网址获取图片UIImage *myImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:myURL]];
答案 1 :(得分:0)
很容易,
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);