Model.h
#import <Foundation/Foundation.h>
typedef void(^HouBlock)(NSDictionary *relust);
@interface Hou : NSObject
//解析方法
+(void) httpGet:(NSString *)UrlString Cyy:(NSDictionary *) paramneters relust:(HouBlock)relust;
@end
Model.m
#import "Hou.h"
#import "AFNetworking.h"
@implementation Hou
+(void)httpGet:(NSString *)UrlString Cyy:(NSDictionary *)paramneters relust:(HouBlock)relust
{
AFHTTPSessionManager *Manger=[AFHTTPSessionManager manager];
Manger.responseSerializer = [AFHTTPResponseSerializer serializer];
[Manger GET:UrlString parameters:paramneters progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
id obj = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:NULL];
// NSDictionary *dict = obj[@"weatherinfo"];
relust(obj);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
}];
}
@end
获取网络数据
//获取网址数据
NSString *url=@"http://app.cad.com.cn/cad.php?method=channel&cid=88&page=1&limit=10";
[Hou httpGet:url Cyy:nil relust:^(NSDictionary *relust) {
NSArray *arr=relust[@"data"];
_arraya = [[NSMutableArray alloc] init];
// NSLog(@"%@",arr);
for (int i=0; i