2013-12-18 69 views
0

你好,我填寫了一個NSMutableArray與字典,我需要郵寄發送到服務器(我使用AFNetworking),但我得到<null>響應,我如何發佈數組以獲得一個OK響應?下面我展示的代碼:發佈到服務器NSMutableArray與字典

NSDictionary *[email protected]{@"contacts":array}; 
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:[NSURL  URLWithString:@"https://www.angelpolitics.com"]]; 

[httpClient setDefaultHeader:@"Content-Type" value:@"application/json"]; 
[httpClient setParameterEncoding:AFJSONParameterEncoding]; 
NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" 
                 path:@"/mobile/ios_contact.php" 
                parameters:dict 
           ]; 

AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { 



    if (JSON !=nil) { 

     [SVProgressHUD dismiss]; 

     NSLog(@"Result contacts %@",JSON); 


     if ([[JSON objectForKey:@"a"]isEqualToString:@"Ok"]) { 


      UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Notification" message:@"Leads add succesfully" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 

      [alertView show]; 

      [self.delegate dismissController:self]; 


      NSLog(@"Resulta AddLeads %@",JSON); 
     } 





    }else{ 


     UIAlertView *alertView=[[UIAlertView alloc]initWithTitle:@"Error" message:@"Data do not send try again, please" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil]; 

     [alertView show]; 



    } 



} failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { 
    NSLog(@"error %@", [error description]); 

}]; 

operation.acceptableContentTypes=[NSSet setWithObjects:@"application/json",@"text/json",@"text/html", nil]; 




[queue addOperation:operation]; 

和數組是如下:

(
     { 
     email = "N/A"; 
     lastname = Doe; 
     name = John; 
     phone = "(555) 555-55"; 
    }, 
     { 
     email = "N/A"; 
     lastname = Poppins; 
     name = Mary; 
     phone = "(333) 333-333"; 
    }, 
     { 
     email = "N/A"; 
     lastname = Skywalker; 
     name = Luke; 
     phone = "(222) 222-2222"; 
    } 
) 
+0

服務器返回什麼代碼? – Miroslav

回答

0

現在是多少,使用更加簡單AFNetworking 2.0(你將不得不再次下載和集成框架):

NSDictionary *[email protected]{@"contacts":array}; 
NSString * urlString = @"https://www.angelpolitics.com/mobile/ios_contact.php"; 
[[AFHTTPRequestOperationManager manager] POST:urlString parameters:dict success:^(AFHTTPRequestOperation *operation, id responseObject) { 
    NSLog(@"response : %@", responseObject); 
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { 
    NSLog(@"Error : %@", error.localizedDescription); 
}]; 

而且大多是,它依賴於Web開發人員,他如何又發展了Web服務,他是如何預期的數據在到達。

+0

以及他如何處理成功,它不會是第一個返回導致JSON解析器失敗的無效JSON響應的Web開發人員。 –

+0

那麼這是超越他,並與網絡開發人員的談話不會傷害 –

+0

我與網絡開發人員交談,都試圖解決這個問題,但我的問題是:我如何將數組發送到字典好?因爲後端開發人員告訴我,收到「(」而不是「[」 – frank0ch0a