您好,登錄后才能下訂單哦!
創建get請求,
1.將網址初始化成一個OC字符串對象.
NSString * urlString = [NSString stringWithFormat:@"%@?query=%@®ion=%@&output=json&ak=6E823f587c95f0148c19993539b99295",kBusinessInfoURL,@"銀行",@"濟南"];
如果網址中存在中文,進行轉碼
NSString * urlString = @"http://p_w_picpath.zcool.com.cn/56/13/1308200901454.jpg";
NSString * newURLString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
2.構建網絡URL對象
NSURL * url = [NSURL URLWithString:newURLString];
//3.創建網絡請求
NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
3.創建同步連接.
NSURLResponse * response = nil;
NSError * error = nil;
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
4.解析
NSDictionary * dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(@"%@",dic);
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。