美文网首页关爱小白
afn post请求解析返回数据

afn post请求解析返回数据

作者: thinkwick | 来源:发表于2017-08-01 16:01 被阅读10次

    NSString*svr =@"这里是服务器给的地址";

    //这是和后台定好的参数

    NSDictionary*parameters =@{@"userID":pic_useridstr,@"title":pl_NSnei(grdt_biaoti),@"XXcontent":pl_NSnei(grdt_neirong),@"Picpath":pl_NSnei(tuPianN)};

    AFHTTPSessionManager*manager = [AFHTTPSessionManagermanager];

    manager.requestSerializer= [AFJSONRequestSerializerserializer];

    manager.responseSerializer= [AFHTTPResponseSerializerserializer];

    [manager.requestSerializersetValue:@"text/html"forHTTPHeaderField:@"Content-Type"];

    manager.responseSerializer.acceptableContentTypes= [NSSetsetWithObjects:@"application/json",@"text/json",@"text/javascript",@"text/html",@"image/png",@"image/jpeg",nil];

    [managerPOST:svrparameters:parametersprogress:nilsuccess:^(NSURLSessionDataTask*_Nonnulltask,NSDictionary*responseObject) {

    ///关键是下面这一句  如果后台返回responseObject 是json 的得用这句转 不然会报错

    NSDictionary*dic = [NSJSONSerializationJSONObjectWithData:(NSData*)responseObjectoptions:NSJSONReadingMutableContainerserror:nil];

    intstatus = [dic[@"status"]intValue];

    }failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {

    NSLog(@"失败:%@",error);

    }];

    相关文章

      网友评论

        本文标题:afn post请求解析返回数据

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