美文网首页
IOS Get请求

IOS Get请求

作者: abios | 来源:发表于2016-05-24 16:17 被阅读0次

#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];

相关文章

网友评论

      本文标题:IOS Get请求

      本文链接:https://www.haomeiwen.com/subject/yywrrttx.html