1. Request JSON data, complete with afhttprequestoperation
nsstring *str=[nsstring stringwithformat:@ "http://int.dpool.sina.com.cn/ iplookup/iplookup.php?format=json&ip=218.4.255.255 "]; nsurl *url = [nsurl urlwithstring:[str stringbyaddingpercentescapesusingencoding: nsutf8stringencoding]]; // utf-8 nsurlrequest *request = [NSURLRequest requestWithURL:url]; Afhttprequestoperation *operation = [[afhttprequestoperation alloc]initwithrequest:request ]; // request data, set the callback function for success and failure [operation setcompletionblockwithsuccess:^ (Afhttprequestoperation *operation, id responseobject) { nsstring *html&nBsp;= operation.responsestring; nsdata* data=[html datausingencoding:nsutf8stringencoding]; id dict=[ nsjsonserialization jsonobjectwithdata:data options:0 error:nil]; nslog (@ "The data obtained is:%@", dict); }failure:^ (afhttprequestoperation *operation, nserror *error) { nslog (@ "error occurred! %@ ", error); }]; // join queue nsoperationqueue *queue = [[nsoperationqueue alloc] init]; [ queue addoperation:operation];
IOS afnetworking Request JSON data