如何通过JSON获取图像,我尝试多次但无法获取图像。我想获取图像并设置图像视图和自动幻灯片图像。怎么可能请帮助我。我很累:(
{
"status": [
{
"id": "80",
"slider_image_path": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/uploads\/1464670561-GolfOuting_080715.jpg"
},
{
"id": "81",
"slider_image_path": "http:\/\/edutimeapp.com\/toshow\/chamber-of-commerc\/uploads\/1464708964-facebookGoshenRepair1.jpg"
}
]
}
#import "ViewController.h"
@interface ViewController ()
{
NSArray*namearry;
}
@end
@implementation ViewController
@synthesize imageView;
- (void)viewDidLoad {
[super viewDidLoad];
NSURLRequest *req=[[NSURLRequest alloc]initWithURL:[NSURL URLWithString:@"http://edutimeapp.com/toshow/chamber-of-commerc/ws/fetch_slider.php"]];
response =[[NSMutableData alloc]init];
[NSURLConnection connectionWithRequest:req delegate:self];
imageView.animationImages = namearry;
imageView.animationDuration = 10;
imageView.animationRepeatCount = 0;
[imageView startAnimating];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[response appendData:data];
NSLog(@"error receving data %@",response);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *error;
NSLog(@"Error in receiving data %@",error);
NSMutableDictionary *json = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
NSLog(@"response data %@",json);
NSArray *results = [json objectForKey:@"status"];
namearry = [results valueForKey:@"slider_image_path"];
}
@end