zoukankan      html  css  js  c++  java
  • 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];

  • 相关阅读:
    经典isset,empty,is_null三个的用法与区别,最详细的讲解
    TP框架分页bootstrap冲突问题
    TP框架右下角运行时间
    TP6的跳转坑 和cmd报错 php版本和composer扩展坑
    TP5.1模板继承
    TP5.1模型关联
    Oracle语句
    ajaxform和ajaxgrid获取数据源、添加数据
    confirm和alert弹窗
    UEP-弹窗
  • 原文地址:https://www.cnblogs.com/jiackyan/p/4046742.html
Copyright © 2011-2022 走看看