解析JSON數據圖像這是我的JSON響應,圖像視圖
{
"AppConfig": {
"store_logo": "url",
"deal_status": "A",
"see_the_menu_btn": "A",
"store_id": "3",
"store_name": " Pizza Restaurant",
"bg_image": "www.my image.png"
}
}
NSString *localwthr = [NSString stringWithFormat:@"my url"];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:localwthr]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
if (responsedata) {
NSDictionary *Dictionarydetails = [NSJSONSerialization
JSONObjectWithData:responsedata
options:kNilOptions
error:nil];
NSLog(@"The return data is: %@",Dictionarydetails);
NSString *imgURL=[[Dictionarydetails objectForKey:@"AppConfig"]objectForKey:@"bg_image"];
UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0,0,100,100)];
imageView.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString: imgURL]]];
}
}
我需要獲得關鍵bg_image
,下載圖像URL值,並將其設置在UIImageView
。我怎樣才能做到這一點?
發佈您到目前爲止完成您所需要的代碼。 – rmaddy
NSString * localwthr = [NSString stringWithFormat:@「my url」]; NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:localwthr]]; [[NSURLConnection alloc] initWithRequest:request delegate:self]; – user3251949
好的,你發佈了代碼。怎麼了?你不告訴我們問題是什麼。 – rmaddy