2014-04-11 135 views
0
"weatherIconUrl": [ 
{ 
"value": "http://cdn.worldweatheronline.net/images/wsymbols01_png_64/wsymbol_0001_sunny.png" 
} 
], 

图像的URL,这是我的JSON数据,我可以能够获取文本类型的数据,但我可以不能够从weatherIconUrl数组提取图像URL如何解析来自JSON

+2

你的问题是有点混乱。你问如何从JSON中获取url或如何从url中获取图片? – Inertiatic

+0

你想显示图像从JSon的网址 –

+0

是的,我想显示图像 – user3509615

回答

2

使用下面的一行代码拿到钥匙@"value"

NSString * imgURLString = [[[myMaindictonary objectForKey:@"weatherIconUrl"] objectAtIndex:0] objectForKey:@"value"]; 

值并将其转换该字符串URL

NSURL *myURL = [NSURL URLWithString:[imgURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

,你可以一LSO通过

UIImage *myImg = [UIImage imageWithData:[NSData dataWithContentsOfURL:myURL]]; 
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);