數(shù)據(jù)解析

model 層

? ? ? .h 文件 ?

- (instancetype)initModel: (NSDictionary *)dic;

+ (instancetype)HuiDiao: (NSDictionary *)dic;

.m ?

- (instancetype)initModel: (NSDictionary *)dic

{

if (self = [super init])

{

[self setValuesForKeysWithDictionary:dic];

}

return self;

}

+ (instancetype)HuiDiao: (NSDictionary *)dic

{

return? [[self alloc]initModel:dic];

}

表格中自定義cell 利用第三方 展示圖片"SDWebImage"

#import "UIImageView+WebCache.h"

[cell.imageVi sd_setImageWithURL:[NSURL URLWithString:model.pic] placeholderImage:[UIImage imageNamed:@"3dcbc92925711f3d!400x400_big.jpg"] completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {

}];




block 傳值 ?業(yè)務(wù)處理層. h

typedef void (^shipinBlock)(NSMutableArray *arr);

//聲明 block 屬性

@property (nonatomic,strong) shipinBlock shujublock;

+ (instancetype)DL;

//用于回傳數(shù)據(jù)的方法

//聲明block 的方法

//-(void)shujuchuanzhi:(shujuBlock)shuju;

- (void)GETJSON:(NSString *)urlStr shujuchuanzhi:(shipinBlock)shuju;




//業(yè)務(wù)處理層. m

+ (instancetype)DL

{

if (shipin == nil)

{

shipin = [[shipinDataBase alloc]init];

}

return shipin;

}

-(void)GETJSON:(NSString *)yaowenUrlStr shujuchuanzhi:(shipinBlock)shuju

{

_dic = [[NSMutableDictionary alloc]init];

_allarr = [NSMutableArray array];

//NSURL *url = [NSURL URLWithString:yaowenUrlStr];

//創(chuàng)建管理器

AFHTTPSessionManager *manage = [AFHTTPSessionManager manager];

manage.responseSerializer = [[AFHTTPResponseSerializer alloc]init];

NSString *str = [shipinUrlstr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[manage GET:str parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {

} success:^(NSURLSessionDataTask * _Nonnull task, id? _Nullable responseObject) {

NSLog(@"視頻數(shù)據(jù)獲取成功");

_dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];

//獲取字典里的數(shù)據(jù)

NSMutableArray *arrdata = [_dic objectForKey:@"videoList"];

//遍歷字典

//

for (NSDictionary *dic4 in arrdata) {

//初始化數(shù)據(jù)模型

shipinModel *yaowen = [shipinModel yy_modelWithDictionary:dic4];;

[_allarr addObject:yaowen];

//NSLog(@"++++++++%@",yaowen.mp4_url);

shuju(_allarr);

}

} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {

NSLog(@"獲取失敗");

}];

}

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容