发布JSON时捕获AFJSONRequestOperation错误

时间:2013-11-11 03:25:10

标签: ios objective-c nsmutablearray afnetworking

我正在试图找出我的应用程序发送到我的Web API的JSON有什么问题,因为每次发送消息时它总会通过命令的“失败”块。但是,当我尝试在我的本地测试Web API时,它确实有效,并且确实发布了,所以我的猜测是在我创建消息时发送的JSON有问题。这是我的代码:

+ (NSArray *)getKeysFighterVM{
    NSMutableArray *keys = [[NSMutableArray alloc] initWithObjects:@"Id",
                            @"EventId", 
                            @"RegistrationId",
                            @"FirstName",
                            @"LastName", nil];
    return keys;
}


-(void)checkInFighterWCFToBracketId:(NSNumber *)bracketId :(void(^)(bool success, NSError *error, id JSON)) block{

    NSArray *requestKeys = [Fighter getWCFKeysFighterVM];
    NSArray *requestValues = [NSArray arrayWithObjects:
                              [NSString stringWithFormat:@"%@", [self.Id stringValue]],
                              [NSString stringWithFormat:@"%@", [self.eventId stringValue]],
                              [NSString stringWithFormat:@"%@", [self.regId stringValue]],
                              [NSNull null],
                              [NSNull null],
                              nil];

    NSDictionary *jsonRequestDictionary = [NSDictionary dictionaryWithObjects:requestValues forKeys:requestKeys];

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"THISWHEREMYAPIURLRESIDES"];


    AFHTTPClient *httpclient = [[AFHTTPClient alloc] initWithBaseURL:url];
    httpclient.parameterEncoding = AFJSONParameterEncoding;

    NSMutableURLRequest *request = [httpclient requestWithMethod:@"POST" path:@"" parameters:jsonRequestDictionary];

    AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
        NSLog(@"SUCCESS JSON %@", JSON);
        block(YES, nil, JSON);
    }failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON){
        JSON = [request HTTPBody];
        NSDictionary *jsonDict = (NSDictionary *)JSON;
        NSLog(@"FAILURE ERROR JSON %@", jsonDict);
        NSArray *jsonarray = (NSArray *)JSON;


        NSLog(@"----FAILURE ERROR array %@", jsonarray);


        NSLog(@"FAILURE ERROR USErInfo %@", [error userInfo]);
        block(NO, error, JSON);
    }];

    [operation start];
    [operation waitUntilFinished];
}

所以我尝试回复它看起来像什么但是回来了这样:

  

---- FAILURE ERROR数组< 7b225573 65724964 223a2238 222c2242 69727468 44617465 223a6e75 6c6c2c22 41636164 656d794e 616d6522 3a6e756c   6c2c2246 69727374 4e616d65 223a6e75 6c6c2c22 4c617374 4e616d65   223a6e75 6c6c2c22 4576656e 74496422 3a223522 2c224576 656e7446   69676874 65725265 67697374 72617469 6f6e4964 223a2235 227d>

0 个答案:

没有答案