Afnetworking 3.0 Post方法

时间:2015-11-27 06:10:57

标签: objective-c json http-post

NSDictionary *parameters=[[NSDictionary alloc]initWithObjectsAndKeys:@"1",@"brand.brand_id",
                               @"1",@"city.city_id",
                               @"9911223344",@"mobile",
                               @"aravind",@"first_name",
                               @"Buddarapu",@"last_name",
                               @"anand@gmail.com",@"email",
                               @"21-12-1991",@"date_of_birth",
                               @"Male",@"gendername",
                               @"0",@"isadmin",
                               @"1",@"location.location_id",
                               @"1",@"organization.organization_id",
                               @"helloIndia",@"passwordhash",
                               @"1",@"preference.preference_id",
                               @"1",@"state",
                               @"BAnand",@"username",
                               @"",@"verifypass",nil];


    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];

    AFJSONRequestSerializer *serializer = [AFJSONRequestSerializer serializer];
    [serializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [serializer setValue:@"application/json" forHTTPHeaderField:@"Accept"];
    manager.requestSerializer = serializer;


    [manager POST:@"http://*.***.**.***:****/SaveCustomer" parameters:parameters success:^(NSURLSessionDataTask *  task, id   responseObject) {

        NSLog(@"Responce is :%@",responseObject);


        } failure:^(NSURLSessionDataTask *  task, NSError *  error) {
        NSLog(@"error %@",error);
    }];

   }

调用服务器时出现此错误。

  

错误错误域= NSCocoaErrorDomain代码= 3840" JSON文本没有   从数组或对象和选项开始,以允许未设置片段。"   UserInfo = {NSDebugDescription = JSON文本不是以数组或   允许片段未设置的对象和选项。}

1 个答案:

答案 0 :(得分:0)

这通常可能是您的返回数据未进行JSON编码的结果。尝试将从服务器返回的数据编码为JSON格式。