afn post请求解析返回数据

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请求解析返回数据)