Ios 如何从json解析图像URL
这是我的json数据,我可以获取文本类型的数据,但无法从weatherIconUrl数组获取图像url 并将此字符串转换为URLIos 如何从json解析图像URL,ios,objective-c,json,parsing,Ios,Objective C,Json,Parsing,这是我的json数据,我可以获取文本类型的数据,但无法从weatherIconUrl数组获取图像url 并将此字符串转换为URL NSString * imgURLString = [[[myMaindictonary objectForKey:@"weatherIconUrl"] objectAtIndex:0] objectForKey:@"value"]; 您还可以通过以下方式从该URL获取图像: NSURL *myURL = [NSURL URLWithString:[imgURLSt
NSString * imgURLString = [[[myMaindictonary objectForKey:@"weatherIconUrl"] objectAtIndex:0] objectForKey:@"value"];
您还可以通过以下方式从该URL获取图像:
NSURL *myURL = [NSURL URLWithString:[imgURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
很容易,
UIImage *myImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:myURL]];
你的问题有点让人困惑。你是在问如何从JSON中获取url还是如何从url中获取图像?你想从JSON url中显示图像是的,我想显示图像
UIImage *myImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:myURL]];
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);