CodeGuru CodeGuru - 5 months ago 17
iOS Question

Pass NSArray as parameter in AFNetworking

How to pass NSArray as a parameter in AFNetworking?
API which i am trying to call is expecting a list(array).
I cannot use dictionary because their is no key.

Answer
 AFHTTPRequestOperationManager *manager;

 manager = [AFHTTPRequestOperationManager manager];
 manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setTimeoutInterval:500.0];
[manager POST:strRequestUrl parameters:yourArray success:^(AFHTTPRequestOperation *operation, id responseObject)
{

     NSString *msg;
     NSData *jsonData = [NSJSONSerialization dataWithJSONObject:responseObject
                                                               options:NSJSONWritingPrettyPrinted
                                                                 error:nil];
     NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

 } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
 }];