2014-04-11 133 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);