So, basically I am trying to make a JSON Request against a WS in which one of its parameter is an Array using AFNetworking 3.0 My Json should look something like:
{
"filtrosAlerta": [
{
"data": "",
"type": ""
}
],
"frecuency": 0
}
The backend error doesn't say much really (Request failed: internal server error (500)) but after troubleshooting this in different ways, the Array inside the Dictionary seems to be the problem. So I am sending the following request through AFNetworking 3.0:
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
manager.requestSerializer = serializer;
[manager.requestSerializer setAuthorizationHeaderFieldWithCredential:credential];
manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html",nil];
NSString *url = @"http://www.example.com/webservice"
NSArray *filters = @[@{@"data" : @"java", @"type" :@"query"}, @{@"data" : @"29", @"type" :@"provincia"}];
NSDictionary *parameters = @{@"filtrosAlerta":filters, @"frecuenciaNotif":[NSNumber numberWithInt:0]]
[manager POST:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nullable task, id response) {
completionBlock(response, nil);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
completionBlock(nil, error);
}];
My problem is that when I add the NSArray inside the NSDictionary I get an error from the backend server. If I try to debug the "parameters" NSDictionary inside xcode I get the following thing:
{filtrosAlerta = ({data = java;type = query;}{data = 29;type = provincia;});
frecuenciaNotif = 7;}
Please note that instead of the normal "[]" Json Array I seem to be getting a "()" array which doesn't seem to be right, but this is really xcode debugger, and I believe that eventually AFNetworking will get each object inside the NSDictionary and create the proper JSON string! I've been looking around and tried different answers but could not get this working yet.