AFNetworking 使用总结

NSString *URLTmp = @"";

    NSString *URLTmp1 = [URLTmp stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];  //转码成UTF-8  否则可能会出现错误

    URLTmp = URLTmp1;

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString: URLTmp]];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

        NSLog(@"Success: %@", operation.responseString);

        NSString *requestTmp = [NSString stringWithString:operation.responseString];

        NSData *resData = [[NSData alloc] initWithData:[requestTmp dataUsingEncoding:NSUTF8StringEncoding]];

        //系统自带JSON解析

        NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableLeaves error:nil];

        

         NSLog(@"resultDic: %@", resultDic);

        

    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {

        NSLog(@"Failure: %@", error);

       // [SVProgressHUD dismissWithError:@"提交失败,请重试"];

    }];

    [operation start];

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。