使用afnetworking我得到這個錯誤,而張貼的JSON到網址:無法投遞JSON在IOS
Invalid top-level type in JSON write'
我使用afnetworking POST請求的代碼,甚至發送完美JSON但它不斷給我的錯誤。
我的代碼:
NSString * serviceType = @"xyz";
NSString * remarks [email protected]"project deadline is near ";
NSString * emailId = @"xyx.live.com";
NSDictionary *params =
@ {
@"serviceType" :serviceType,
@"remarks" :remarks,
@"emailId" :emailId
};
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params
options:0
error:&error];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
AFHTTPRequestOperationManager *manager2 = [AFHTTPRequestOperationManager manager];
AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
[serializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[serializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
manager2.requestSerializer = serializer;
[manager2 POST:@"http://xyx.com" parameters:jsonString success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON_post_fzzlogin: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//here is place for code executed in success case
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error while sending POST"
message:@"Sorry, try again."
delegate:nil
cancelButtonTitle:@"Ok"
otherButtonTitles:nil];
[alertView show];
NSLog(@"Error: %@", error);
}];
請幫我出這方面.thanks提前