【问题标题】:Pass multiple params with same key with different value + AFnetworking传递具有不同值的相同键的多个参数+ AFnetworking
【发布时间】:2015-12-29 04:02:36
【问题描述】:

我想使用 AFNetworking 传递具有不同值的相同键的多个参数,请查看我的代码。

NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
[dic setValue:@"1" forKey:@"UserID"];
[dic setValue:@"12" forKey:@"catID[]"];
[dic setValue:@"13" forKey:@"catID[]"];
[dic setValue:@"14" forKey:@"catID[]"];
  • 在 iOS 中使用 NSMutableDictionary 无法使用相同的键(POST 方法)传递多个参数。 --> 问题:- 有没有其他方法可以用相同的键传递多个参数?

  • 我在我的应用程序中使用 AFNetworking。有什么建议吗?

【问题讨论】:

  • 为什么不使用 catID 数组?我猜 AFNetworking 对此有支持

标签: ios iphone ios8 afnetworking-2


【解决方案1】:

你应该使用AFN的API:

  (NSURLSessionDataTask *)POST:(NSString *)URLString
                    parameters:(id)parameters
     constructingBodyWithBlock:(void (^)(id <AFMultipartFormData> formData))block
                      progress:(nullable void (^)(NSProgress * _Nonnull))uploadProgress
                       success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
                       failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure

你可以看下图

enter image description here

【讨论】:

    【解决方案2】:
    NSMutableDictionary *dic = [[NSMutableDictionary alloc]init];
    [dic setValue:@"1" forKey:@"UserID"];
    
    NSMutableArray *catID = [[NSMutableArray alloc]init];
    [catID addObject:@"12"];
    [catID addObject:@"13"];
    [catID addObject:@"14"];
    
    [dic setObject:catID forKey:@"catID"];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-01-14
      • 2014-04-27
      • 1970-01-01
      • 2014-08-09
      • 1970-01-01
      • 2015-07-20
      • 1970-01-01
      相关资源
      最近更新 更多