簡體   English   中英

使用具有不同值的同一個鍵傳遞多個參數+ AFnetworking

[英]Pass multiple params with same key with different value + AFnetworking

我想使用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。 有什么建議嗎?

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

您應該使用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

你可以看下面的圖片

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM