objective-c如何在 AFNETWORKING 中设置多个值的参数

发布时间: 2016/10/2 4:41:24
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

我想要删除服务器上的多个文件,我需要向服务器发送多个参数的值。前︰ upload_id ="11,12,13",每个值是一个由逗号分隔的字符串。我使用 NSArray,但它不工作。服务器响应落选。这是我的代码︰

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if([_tableView cellForRowAtIndexPath:indexPath].accessoryType == UITableViewCellAccessoryCheckmark){
        [_tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryNone;
    }else{
        [_tableView cellForRowAtIndexPath:indexPath].accessoryType = UITableViewCellAccessoryCheckmark;
    }
    NSArray *selectedRows = [_tableView indexPathsForSelectedRows];

    for (NSIndexPath *indexPath in selectedRows) {
        uploadidString =[uploadidArray objectAtIndex:indexPath.row];
    }
    [iduploadArray insertObject:uploadidString atIndex:0];
    NSLog(@"ID UPLOAD Array %@",iduploadArray);
}

-(void) deleteItems 
{
    NSURL *url1 = [NSURL URLWithString:@"http://myserver"];
    AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL: url1] ;

    NSDictionary *params1 = @{
                              @"upload_id" :  [NSArray arrayWithObjects:iduploadArray,nil],

                              };

    NSMutableURLRequest *afRequest = [httpClient requestWithMethod:@"POST" path:nil parameters:params1] ;
    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:afRequest];

    [operation  setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success");
        NSString * parsexmlinput = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
        NSLog(@"Response in Delete items: %@", parsexmlinput); 
        [self parseXMLFile:parsexmlinput];


    }
                                      failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                          NSLog(@"error: %@", error);

                                      }
     ];
    [httpClient enqueueHTTPRequestOperation:operation];


}

你有建议吗?

解决方法 1:

当你创建参数时,使用 componentsJoinedByString:@"," 上要将它转换成你想要的格式字符串的数组︰

@"upload_id" : [iduploadArray componentsJoinedByString:@","],
官方微信
官方QQ群
31647020