如何通过JSON获取图像,并设置图像滑块?

时间:2016-06-10 07:28:03

标签: objective-c json xcode image slider

如何通过JSON获取图像,我尝试多次但无法获取图像。我想获取图像并设置图像视图和自动幻灯片图像。怎么可能请帮助我。我很累:(

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"
}
          ]

}

的ViewController

 #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

1 个答案:

答案 0 :(得分:0)

从代码中的这一点开始:

HTML

**感谢Daniel Blezek Can I load a UIImage from a URL?