处理服务器参数中有数组参数(AFN框架)

没有选择网上说的修改AFN的源码,而是转换了下跟后端小哥哥商量了下转成相应的json字符串存储。

SQCommentConstModel *constModel = _commentConstArray[currentPage];
        NSMutableArray *cataGoryArray = [NSMutableArray array];
        for(SQCommentLabelModel *model in constModel.labelList){
            if(model.isChoosed){
                NSMutableDictionary *dict = [NSMutableDictionary dictionary];
                [dict setObject:model.labelId forKey:@"labelId"];
                [cataGoryArray addObject:dict];
            }
        }
        NSError *error;
        NSData *jsonData = [NSJSONSerialization dataWithJSONObject:cataGoryArray
                                                           options:NSJSONWritingPrettyPrinted
                                                             error:&error];
        NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
        
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        if(cataGoryArray.count){
            [dict setObject:jsonString forKey:@"labelList"];
        }
        [dict setObject:[LoginUserUtil accessToken] forKey:@"token"];

备参考用。

你可能感兴趣的:(ios_接口联调)