通过 AFNetworking 中的参数的对象数组

Array of objects via parameters in AFNetworking

我可以 POST parameters 如下,如果每个字典项目只有一个项目,它就可以工作。在下面的参数中,我只有一个 pName 和一个 price.

NSMutableDictionary *params= [NSMutableDictionary dictionaryWithDictionary:
                             @{@"pName":pData.pName, 
                             @"price":pData.price,
                             @"notes":pData.notes}];

manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html",nil];
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager POST:URL_SIGNIN parameters:params progress: nil
      success:^(NSURLSessionTask *operation, id responseObject)
 {
     NSLog(@"JSON: %@", responseObject);
 }
 failure:
 ^(NSURLSessionTask *operation, NSError *error) {
     NSLog(@"Error: %@", error);
 }];

但是,我想知道如果我有多个项目,例如 pNames = [Beef, Coffee, Rice ,Sprite]prices = ["", $"3", "", @"1"],我怎么能将项目作为参数。

最后考虑如下对象。

orders = {@"Beef" : @"",@"Coffee" : @"", @"Rice" : @"", @"Sprite" : @""}

假设它是餐厅应用程序,用户选择多个项目进行结帐。

您需要数组 ($[]),而不是字典 (${})。

在你的例子中:

prices = @[@"", @"", @"", @""];

编辑:

作为参数:

NSMutableDictionary *params= [NSMutableDictionary dictionaryWithDictionary:
                             @{@"prices": @[@"", @"", @"", @""]}];

或:

NSArray *prices = @[@"", @"", @"", @""];
NSMutableDictionary *params= [NSMutableDictionary dictionaryWithDictionary:
                                 @{@"prices": prices];