POST方法AFNetworking响应未完成

时间:2016-06-20 13:02:25

标签: objective-c nsarray nsdictionary afnetworking

我希望使用NSDictionary AFNetworking方法发送POST数据,并从服务器获取结果。 我的NSDictionary

{
    "category_id" = "-1";
    "city_id" = "-1";
    "degree_id" = "-1";
    "experience_id" = "-1";
    industries =     (
                {
            id = 2;
        },
                {
            id = 4;
        },
                {
            id = 3;
        }
    );
    "position_id" = "-1";
    "salary_id" = "-1";
    skills =     (
                {
            aa = id;
        },
                {
            aa = asdasda;
        }
    );
    "type_id" = "-1";
}

发送此NSDictionary时,我的服务器会收到我的数据:

{
    "category_id" = "-1";
    "city_id" = "-1";
    "degree_id" = "-1";
    "experience_id" = "-1";
    industries =     (
        2,
        4,
        3
    );
    "position_id" = "-1";
    "salary_id" = "-1";
    skills =     (
        id,
        asdasda
    );
    "type_id" = "-1";
}

我对此很困惑!!!

industry&技能是我的NSDictionary中的字典数组但是当服务器接收时不显示键并且只显示数组中的值!!!

请指导我。

这是我的POST方法:

self.params = [[NSMutableDictionary alloc]init];
    [self.params setObject:[NSNumber numberWithInteger:[self.object.jobCategory integerValue]] forKey:@"category_id"];
    [self.params setObject:[NSNumber numberWithInteger:[self.object.jobCity integerValue]] forKey:@"city_id"];
    [self.params setObject:self.object.industry forKey:@"industries"];
    [self.params setObject:[NSNumber numberWithInteger:[self.object.educationDegree integerValue]] forKey:@"degree_id"];
    [self.params setObject:[NSNumber numberWithInteger:[self.object.experience integerValue]] forKey:@"experience_id"];
    [self.params setObject:[NSNumber numberWithInteger:[self.object.jobType integerValue]] forKey:@"type_id"];
    [self.params setObject:[NSNumber numberWithInteger:[self.object.jobSalary integerValue]] forKey:@"salary_id"];
    [self.params setObject:[NSNumber numberWithInteger:[self.object.jobPosition integerValue]] forKey:@"position_id"];


    [self.params setObject:[NSMutableArray array] forKey:@"skills"];
    [[self.params objectForKey:@"skills"] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"id",@"aa", nil]];
    [[self.params objectForKey:@"skills"] addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:@"asdasda",@"aa", nil]];
    //NSData *jsonData = [NSJSONSerialization dataWithJSONObject:self.params options:NSJSONWritingPrettyPrinted error:nil];
    //NSString *str = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
    NSLog(@"%@",self.params);
    NSString* path = [NSString stringWithFormat:@"%@%@" , [PublicMethods getStrings:@"url"],[PublicMethods getStrings:@"searchJob"]];
    [self.network callPOSTWebServiceWithPath:path AndWithParameters:self.params withCallback:^(NSDictionary *result)
     {
         NSLog(@"%@",result);
         if ([[result objectForKey:@"result"]boolValue])
         {
             NSLog(@"%@",[result objectForKey:@"data"]);
         }
         else
         {
             //error accured
         }

     }];

1 个答案:

答案 0 :(得分:0)

这是一个非常容易的问题。 您发送的字符串数据包括NSDictionary嵌套的NSArray。 但是你把它发送到服务器。 您的阵列中存在相同键的行业和技能代码。 所以当它发送到服务器,然后返回没有密钥的值。这是正确的。

想用密钥查看你的返回值。只需更改你的id,如id1,id2,id3。至于它,aa的变量就是这样。

最后,您将看到返回值的键。 祝你好运!