[英]how to display horizontal scrollview of images from the JSON
my JSON response我的 JSON 响应
{"result":0,"data":[{"bannerslider_id":"1","img":"http:\/\/whatsinthestreet.com\/media\/bannerslider\/images\/slider1.jpg"},{"bannerslider_id":"2","img":"http:\/\/whatsinthestreet.com\/media\/bannerslider\/images\/slider2.jpg"},{"bannerslider_id":"3","img":"http:\/\/whatsinthestreet.com\/media\/bannerslider\/images\/slider3.jpg"},{"bannerslider_id":"4","img":"http:\/\/whatsinthestreet.com\/media\/bannerslider\/images\/slider4.jpg"}]}
I wrote code like this我写了这样的代码
(void)viewDidAppear:(BOOL)animated{
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"http://whatsinthestreet.com/allbanners.php"] completionHandler:^(NSData * _Nullable data ,NSURLResponse * _Nullable response,NSError * _Nullable error){
NSLog(@"response %@",response);
NSLog(@"data %@",data);
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSLog(@"dict%@",dict);
NSArray *array;
array=[dict valueForKey:@"data"];
NSLog(@"%@",array);
I got the response as我得到了回应
dict{
data = (
{
"bannerslider_id" = 1;
img = "http://whatsinthestreet.com/media/bannerslider/images/slider1.jpg";
},
{
"bannerslider_id" = 2;
img = "http://whatsinthestreet.com/media/bannerslider/images/slider2.jpg";
},
{
"bannerslider_id" = 3;
img = "http://whatsinthestreet.com/media/bannerslider/images/slider3.jpg";
},
{
"bannerslider_id" = 4;
img = "http://whatsinthestreet.com/media/bannerslider/images/slider4.jpg";
}
);
result = 0;
}
How can I access the image from these values to get horizontal scrollview of images?如何从这些值访问图像以获得图像的水平滚动视图?
This should work for you.这应该对你有用。
-(void)viewDidAppear:(BOOL)animated{
[[[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@"http://whatsinthestreet.com/allbanners.php"] completionHandler:^(NSData * _Nullable data ,NSURLResponse * _Nullable response,NSError * _Nullable error){
NSLog(@"response %@",response);
NSLog(@"data %@",data);
NSDictionary *dict=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
NSLog(@"dict%@",dict);
NSArray *array;
array=[dict objectForKey:@"data"];
NSLog(@"%@",array);
for(id obj in array)
{
NSString *urlStr=[obj objectForKey:@"img"];
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.