2016-06-20 98 views
0

我想發送NSDictionary數據與AFNetworkingPOST方法並從服務器獲取結果。 這是我NSDictionaryPOST方法AFNetworking響應未完成

{ 
    "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 
     } 

    }]; 
+0

你顯示的第二個日誌是'self.params'?你是否記錄了'self.object.industry'來檢查它是否正確?什麼是日誌'[self.params objectForKey:@「skills」]'?我看不出有什麼問題。 – Larme

+0

@Larme我的朋友,當我登錄[self.params objectForKey:@ 「技能」]顯示我:技能=( { AA = ID; },{ AA = asdasda; } ) – kasiri182

回答

0

這是一個非常簡單的問題。 您發送一個字符串數據,其中包括NSDictionary嵌套NSArray。 但是你把它發送到服務器。 您的行業和技能代碼在陣列中具有相同的關鍵字。 所以當它發送到服務器,然後返回值沒有鍵。這是正確的。

想看看你的返回值與key.Just改變你的id喜歡id1,id2,id3。至於它,aa的變量就像那樣。

最後,你會看到鍵值被返回。 祝你好運!

+0

我的朋友我將我的密鑰更改爲id1和id2,但我遇到了這個問題! – kasiri182

+0

嘗試這樣做 產業=( { 「ID」= 「2」 },{ 「ID」= 「4」 },{ 「ID」= 「3」 } ) –