我能够POST
parameters
如下,它适用于如果我只有一个项目的每个字典项目。在以下参数中,我只有一个pName
和一个price
。通过AFNetworking中的参数对象的数组
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 = ["$10", $"3", "$5", @"1"]
。
最后考虑下面的对象。
orders = {@"Beef" : @"$10",@"Coffee" : @"$3", @"Rice" : @"$5", @"Sprite" : @"$1"}
假设它是餐厅应用程序,其中用户选择多个项目退房。
根据Web API的文档:'的NSArray * params = @ [@ {@“pName”:pData.pName,@“price”: pData.price,@“notes”:pData.notes},@ {@“pName”:pData2.pName,@“price”:pData2.price,@“notes”:pData2.notes}等];'或'@pData2.price',@ [pData.price,pData2.price等],@“notes”:@ [pData.price,pData2.price等] pData.notes,pData2.notes,...]},但第一个解决方案似乎更多的逻辑。 – Larme
非常感谢Larme,感谢您介绍面向对象的方式。 – hotspring