#define HOT_TYPE_URL @"http://api.avatardata.cn/Nba/NomalRace"
#define HOTSPOT_KEY @"4d14a70e6d97474ea25dbd5ba35c9c0c"
//获得网址字符串
NSString*urlString = [NSString stringWithFormat:@"%@?key=%@",HOT_TYPE_URL,HOTSPOT_KEY];
//创建URL
NSURL*URL = [NSURLURLWithString:urlString];
//创建网络请求配置
NSURLRequest*request = [NSURLRequest requestWithURL:URL];
//创建session单例
NSURLSession*session = [NSURLSession sharedSession];
NSURLSessionDataTask*task = [session dataTaskWithRequest:request completionHandler:^(NSData*_Nullable data,NSURLResponse*_Nullable response,NSError*_Nullable error) {
//数据解析 json - >字典
id object = [NSJSONSerializationJSONObjectWithData:dataoptions:NSJSONReadingMutableContainers error:nil];
_dataSource= [object[@"result"]mutableCopy];
NSLog(@"%@",_dataSource);
//刷新数据(返回主线程刷新数据)
}];
//开始数据请求
[taskresume];
网友评论