我需要使用AFNetworking
这个问题来构建这样的URL ,{
以及}
如何通过parameter
/api/sth.json?filter[condition]={"53891":[123],"53892":[123,124]}
所以我的代码看起来像这样(我更简单):
[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); }];
但它产生的不是预期的产量:
/api/sth.json?filter[condition][53891][]=123&filter[condition][53892][]=123&filter[condition][53892][]=124
有一种方法可以在parameters
in AFHTTPRequestOperation
或手动我必须把它放入字符串?
编辑:
我目前的解决方案是这样的:
+(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; }
输入字典是:
@{@"53892" : @[@(123),@(124)]}
但它只不过是字符串比较.没有更聪明的方法来直接实现AFNetworking,因为它是相当标准的URL参数?