我想用AFNetworking
POST
方法发送NSDictionary
数据并从服务器获得结果。这是我的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";
}
我对此感到困惑!
工业&技能是我的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
}
}];
这是一个非常容易的问题。您发送一个字符串数据,其中包括Nsdictionary Nested NSarray。但是您将其发送到服务器。您的行业和技能守则,阵列中有相同的关键。因此,当它发送到服务器时,然后在没有键的情况下返回值。
想用键看到您的返回值。恰恰更改您的ID喜欢ID1,ID2,ID3。至于它,AA的变量就是这样。
最后,您会看到返回具有值的键。祝你好运