使用具有不同值的相同密钥传递多个参数+ AFnetworking

时间:2015-10-01 07:31:05

标签: ios iphone ios8 afnetworking-2

我想使用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[]"];
  • 在使用NSMutableDictionary的iOS中,无法使用相同的密钥传递多个参数(POST方法)。 - >问题: - 是否有其他方法可以使用相同的密钥传递多个参数?

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

2 个答案:

答案 0 :(得分:0)

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"];

答案 1 :(得分:0)

您应该使用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