Xcode 代码片段

自制接口和解析

2019-06-25  本文已影响0人  _YN

如果您在阅读我的文章时有疑问 , 请点击这里

创建json文件 , 上传到阿里云
{
    "data":[
                {"lunbopic":"https://lyn326.oss-cn-beijing.aliyuncs.com/RedSquare/lunbo/shop1.jpeg"},
                {"lunbopic":"https://lyn326.oss-cn-beijing.aliyuncs.com/RedSquare/lunbo/shop2.jpeg"},
                {"lunbopic":"https://lyn326.oss-cn-beijing.aliyuncs.com/RedSquare/lunbo/shop3.jpeg"},
                {"lunbopic":"https://lyn326.oss-cn-beijing.aliyuncs.com/RedSquare/lunbo/shop4.jpeg"}
          ]
}

解析

AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/xml", nil];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager GET:@"https://lyn326.oss-cn-beijing.aliyuncs.com/RedSquare/ShopZhongXin/ShopZhongXin.json" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSLog(@"成功 : %@",responseObject);
        dispatch_async(dispatch_get_main_queue(), ^{
                [self.tableView reloadData];
            });
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"失败 : %@",error);
    }];
上一篇 下一篇

猜你喜欢

热点阅读