I need to construct URL like this using AFNetworking
the problem for me it's {
and }
how to pass throught parameter
/api/sth.json?filter[condition]={"53891":[123],"53892":[123,124]}
So my code looks like this (i made it simpler):
[self GET:myUrl parameters:@{
@"filter" : @{
@"condition" : @{
@"53891" : @[@(123)],
@"53892" : @[@(123),@(124)]}
},
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
success(operation,responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
failure(operation,error);
}];
But it's produce not expected output:
/api/sth.json?filter[condition][53891][]=123&filter[condition][53892][]=123&filter[condition][53892][]=124
There is a way to do this in parameters
in AFHTTPRequestOperation
or manually i have to put it into string?
EDIT:
My current solution is like that:
+(NSString*)convertFromDictionary:(NSDictionary*)dic {
NSMutableString *outputStr = [NSMutableString new];
[outputStr appendString:@"{"];
NSArray *allKeys = [[dic allKeys] sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:nil ascending:NO]]];
for(NSString *key in allKeys) {
NSArray *objects = dic[key];
[outputStr appendString:[NSString stringWithFormat:@"\"%@\":[",key]];
for(NSNumber *nb in objects) {
[outputStr appendString:[NSString stringWithFormat:@"%li",[nb longValue]]];
if(![nb isEqual:[objects lastObject]]) {
[outputStr appendString:@","];
} else {
[outputStr appendString:@"]"];
}
}
if(![key isEqual:[allKeys lastObject]]) {
[outputStr appendString:@","];
}
}
[outputStr appendString:@"}"];
return outputStr;
}
Where input dictionary is:
@{@"53892" : @[@(123),@(124)]}
But it's nothing more than string compare. There is no more clever way to achieve it with AFNetworking directly since it's fairly standard URLs parameters?